Skip to content

Commit

Permalink
more on error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Feb 2, 2025
1 parent 062ddff commit 3f591ef
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/test/java/org/htmlunit/javascript/host/StorageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ public void storageEquals() throws Exception {
+ "<script>\n"
+ LOG_TITLE_FUNCTION
+ " try { log('local: ' + (window.localStorage === window.localStorage)); }"
+ " catch(e) { log('exception'); }\n"
+ " catch(e) { log(e.name); }\n"
+ " try { log('session: ' + (window.sessionStorage === window.sessionStorage)); }"
+ " catch(e) { log('exception'); }\n"
+ " catch(e) { log(e.name); }\n"
+ "</script></body></html>";
loadPageVerifyTitle2(html);
}
Expand Down Expand Up @@ -240,19 +240,20 @@ public void localStorageShouldBeShared() throws Exception {
+ "try {\n"
+ " localStorage.clear();\n"
+ " localStorage.setItem('hello', 'I was here');\n"
+ "} catch(e) { log('exception'); }\n"
+ "} catch(e) { log(e.name); }\n"
+ "</script></body></html>";
final WebDriver driver = loadPage2(html1);
final List<String> alerts = getCollectedAlerts(driver);

final String html2 = "<html><body><script>\n"
+ "try {\n"
+ " log(localStorage.getItem('hello'));\n"
+ "} catch(e) { log('exception'); }\n"
+ "} catch(e) { log(e.name); }\n"
+ "</script></body></html>";
releaseResources();

getMockWebConnection().setResponse(URL_FIRST, html2);

releaseResources();
// we have to control 2nd driver by ourself
WebDriver driver2 = null;
try {
Expand All @@ -263,6 +264,7 @@ public void localStorageShouldBeShared() throws Exception {
assertEquals(getExpectedAlerts(), alerts);
}
finally {
driver2.close();
if (!(driver2 instanceof HtmlUnitDriver)) {
shutDownAll();
}
Expand Down Expand Up @@ -291,7 +293,7 @@ public void prototypeIsExtensible() throws Exception {
+ " log('localStorage.extraMethod not callable');\n"
+ " }\n"
+ " log(localStorage.getItem('extraMethod'));\n"
+ "} catch (e) { log('exception'); }\n"
+ "} catch (e) { log(e.name); }\n"
+ "</script></body></html>";
loadPageVerifyTitle2(html);
}
Expand All @@ -312,7 +314,7 @@ public void prototypePropertiesAreVisible() throws Exception {
+ " localStorage.setItem('hasOwnProperty', 'value');\n"
+ " log(typeof localStorage.hasOwnProperty);\n"
+ " log(localStorage.getItem('hasOwnProperty'));\n"
+ "} catch (e) { log('exception'); }\n"
+ "} catch (e) { log(e.name); }\n"
+ " log(localStorage.length);\n"
+ "</script></body></html>";
loadPageVerifyTitle2(html);
Expand All @@ -339,7 +341,7 @@ public void writeToPrototypeProperty() throws Exception {
+ " log(typeof localStorage.hasOwnProperty);\n"
+ " log(localStorage.getItem('hasOwnProperty'));\n"
+ " log(localStorage.length);\n"
+ "} catch (e) { log('exception'); }\n"
+ "} catch (e) { log(e.name); }\n"
+ "</script></body></html>";
loadPageVerifyTitle2(html);
}
Expand Down

0 comments on commit 3f591ef

Please sign in to comment.