Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/utf_string_conversions.h" | |
| 5 #include "chrome/browser/automation/automation_util.h" | 6 #include "chrome/browser/automation/automation_util.h" |
| 6 #include "chrome/browser/extensions/platform_app_browsertest_util.h" | 7 #include "chrome/browser/extensions/platform_app_browsertest_util.h" |
| 7 #include "chrome/browser/ui/browser_tabstrip.h" | 8 #include "chrome/browser/ui/browser_tabstrip.h" |
| 8 #include "chrome/test/base/ui_test_utils.h" | 9 #include "chrome/test/base/ui_test_utils.h" |
| 9 #include "chrome/test/base/test_launcher_utils.h" | 10 #include "chrome/test/base/test_launcher_utils.h" |
| 10 #include "content/public/browser/notification_service.h" | 11 #include "content/public/browser/notification_service.h" |
| 11 #include "content/public/browser/render_process_host.h" | 12 #include "content/public/browser/render_process_host.h" |
| 12 #include "content/public/test/browser_test_utils.h" | 13 #include "content/public/test/browser_test_utils.h" |
| 13 #include "ui/compositor/compositor_setup.h" | 14 #include "ui/compositor/compositor_setup.h" |
| 14 #include "ui/gl/gl_switches.h" | 15 #include "ui/gl/gl_switches.h" |
| 15 | 16 |
| 16 class WebViewTest : public extensions::PlatformAppBrowserTest { | 17 class WebViewTest : public extensions::PlatformAppBrowserTest { |
| 17 protected: | 18 protected: |
| 18 virtual void SetUpCommandLine(CommandLine* command_line) { | 19 virtual void SetUpCommandLine(CommandLine* command_line) { |
| 19 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); | 20 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); |
| 20 #if !defined(OS_MACOSX) | 21 #if !defined(OS_MACOSX) |
| 21 CHECK(test_launcher_utils::OverrideGLImplementation( | 22 CHECK(test_launcher_utils::OverrideGLImplementation( |
| 22 command_line, gfx::kGLImplementationOSMesaName)) << | 23 command_line, gfx::kGLImplementationOSMesaName)) << |
| 23 "kUseGL must not be set by test framework code!"; | 24 "kUseGL must not be set by test framework code!"; |
| 24 #endif | 25 #endif |
| 25 ui::DisableTestCompositor(); | 26 ui::DisableTestCompositor(); |
| 26 } | 27 } |
| 28 | |
| 29 // This method is responsible for initializing a packaged app, which contains | |
| 30 // multiple webview tags. The tags have different partition identifiers and | |
| 31 // their WebContent objects are returned as output. The method also verifies | |
| 32 // the expected process allocation and storage partition assignment. | |
| 33 // The |navigate_to_url| paramter is used to navigate the main browser window. | |
| 34 void NavigateAndOpenAppForIsolation( | |
| 35 GURL navigate_to_url, | |
| 36 content::WebContents** contents1, | |
|
Charlie Reis
2012/11/07 02:36:34
I think you missed my comments in this file, perha
nasko
2012/11/07 17:47:01
Done.
| |
| 37 content::WebContents** contents2, | |
| 38 content::WebContents** storage_contents1, | |
| 39 content::WebContents** storage_contents2) { | |
| 40 GURL::Replacements replace_host; | |
| 41 std::string host_str("localhost"); // Must stay in scope with replace_host. | |
| 42 replace_host.SetHostStr(host_str); | |
| 43 | |
| 44 navigate_to_url = navigate_to_url.ReplaceComponents(replace_host); | |
| 45 | |
| 46 GURL tag_url1 = test_server()->GetURL( | |
| 47 "files/extensions/platform_apps/web_view_isolation/cookie.html"); | |
| 48 tag_url1 = tag_url1.ReplaceComponents(replace_host); | |
| 49 GURL tag_url2 = test_server()->GetURL( | |
| 50 "files/extensions/platform_apps/web_view_isolation/cookie2.html"); | |
| 51 tag_url2 = tag_url2.ReplaceComponents(replace_host); | |
| 52 GURL tag_url3 = test_server()->GetURL( | |
| 53 "files/extensions/platform_apps/web_view_isolation/storage1.html"); | |
| 54 tag_url3 = tag_url3.ReplaceComponents(replace_host); | |
| 55 GURL tag_url4 = test_server()->GetURL( | |
| 56 "files/extensions/platform_apps/web_view_isolation/storage2.html"); | |
| 57 tag_url4 = tag_url4.ReplaceComponents(replace_host); | |
| 58 | |
| 59 ui_test_utils::NavigateToURLWithDisposition( | |
| 60 browser(), navigate_to_url, CURRENT_TAB, | |
| 61 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
| 62 | |
| 63 ui_test_utils::UrlLoadObserver observer1( | |
| 64 tag_url1, content::NotificationService::AllSources()); | |
| 65 ui_test_utils::UrlLoadObserver observer2( | |
| 66 tag_url2, content::NotificationService::AllSources()); | |
| 67 ui_test_utils::UrlLoadObserver observer3( | |
| 68 tag_url3, content::NotificationService::AllSources()); | |
| 69 ui_test_utils::UrlLoadObserver observer4( | |
| 70 tag_url4, content::NotificationService::AllSources()); | |
| 71 LoadAndLaunchPlatformApp("web_view_isolation"); | |
| 72 observer1.Wait(); | |
| 73 observer2.Wait(); | |
| 74 observer3.Wait(); | |
| 75 observer4.Wait(); | |
| 76 | |
| 77 content::Source<content::NavigationController> source1 = observer1.source(); | |
| 78 EXPECT_TRUE(source1->GetWebContents()->GetRenderProcessHost()->IsGuest()); | |
| 79 content::Source<content::NavigationController> source2 = observer2.source(); | |
| 80 EXPECT_TRUE(source2->GetWebContents()->GetRenderProcessHost()->IsGuest()); | |
| 81 content::Source<content::NavigationController> source3 = observer3.source(); | |
| 82 EXPECT_TRUE(source3->GetWebContents()->GetRenderProcessHost()->IsGuest()); | |
| 83 content::Source<content::NavigationController> source4 = observer4.source(); | |
| 84 EXPECT_TRUE(source4->GetWebContents()->GetRenderProcessHost()->IsGuest()); | |
| 85 | |
| 86 // Tags with the same storage partition are not yet combined in the same | |
| 87 // process. Check this until http://crbug.com/138296 is fixed. | |
| 88 EXPECT_NE(source1->GetWebContents()->GetRenderProcessHost()->GetID(), | |
| 89 source2->GetWebContents()->GetRenderProcessHost()->GetID()); | |
| 90 | |
| 91 // Check that the storage partitions of the first two tags match and are | |
| 92 // different than the other two. | |
| 93 EXPECT_EQ( | |
| 94 source1->GetWebContents()->GetRenderProcessHost()-> | |
| 95 GetStoragePartition(), | |
| 96 source2->GetWebContents()->GetRenderProcessHost()-> | |
| 97 GetStoragePartition()); | |
| 98 EXPECT_EQ( | |
| 99 source3->GetWebContents()->GetRenderProcessHost()-> | |
| 100 GetStoragePartition(), | |
| 101 source4->GetWebContents()->GetRenderProcessHost()-> | |
| 102 GetStoragePartition()); | |
| 103 EXPECT_NE( | |
| 104 source1->GetWebContents()->GetRenderProcessHost()-> | |
| 105 GetStoragePartition(), | |
| 106 source3->GetWebContents()->GetRenderProcessHost()-> | |
| 107 GetStoragePartition()); | |
| 108 | |
| 109 *contents1 = source1->GetWebContents(); | |
| 110 *contents2 = source2->GetWebContents(); | |
| 111 *storage_contents1 = source3->GetWebContents(); | |
| 112 *storage_contents2 = source4->GetWebContents(); | |
| 113 } | |
| 114 | |
| 115 void ExecuteScriptWaitForTitle(content::WebContents* web_contents, | |
| 116 const char* script, | |
| 117 const char* title) { | |
| 118 std::wstring js_script = ASCIIToWide(script); | |
| 119 string16 expected_title(ASCIIToUTF16(title)); | |
| 120 string16 error_title(ASCIIToUTF16("error")); | |
| 121 | |
| 122 content::TitleWatcher title_watcher(web_contents, expected_title); | |
| 123 title_watcher.AlsoWaitForTitle(error_title); | |
| 124 EXPECT_TRUE(content::ExecuteJavaScript(web_contents->GetRenderViewHost(), | |
| 125 std::wstring(), js_script)); | |
| 126 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | |
| 127 } | |
| 27 }; | 128 }; |
| 28 | 129 |
| 29 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim) { | 130 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim) { |
| 30 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view")) << message_; | 131 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view")) << message_; |
| 31 } | 132 } |
| 32 | 133 |
| 33 IN_PROC_BROWSER_TEST_F(WebViewTest, ShimSrcAttribute) { | 134 IN_PROC_BROWSER_TEST_F(WebViewTest, ShimSrcAttribute) { |
| 34 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view_src_attribute")) | 135 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view_src_attribute")) |
| 35 << message_; | 136 << message_; |
| 36 } | 137 } |
| 37 | 138 |
| 38 IN_PROC_BROWSER_TEST_F(WebViewTest, Isolation) { | 139 // This tests cookie isolation for packaged apps with webview tags. It navigates |
| 140 // the main browser window to a page that sets a cookie and loads an app with | |
| 141 // multiple webview tags. Each tag sets a cookie and the test checks the proper | |
| 142 // storage isolation is enforced. | |
| 143 IN_PROC_BROWSER_TEST_F(WebViewTest, CookieIsolation) { | |
| 39 ASSERT_TRUE(StartTestServer()); | 144 ASSERT_TRUE(StartTestServer()); |
| 40 const std::wstring kExpire = | 145 const std::wstring kExpire = |
| 41 L"var expire = new Date(Date.now() + 24 * 60 * 60 * 1000);"; | 146 L"var expire = new Date(Date.now() + 24 * 60 * 60 * 1000);"; |
| 42 std::wstring cookie_script1(kExpire); | 147 std::wstring cookie_script1(kExpire); |
| 43 cookie_script1.append( | 148 cookie_script1.append( |
| 44 L"document.cookie = 'guest1=true; path=/; expires=' + expire + ';';"); | 149 L"document.cookie = 'guest1=true; path=/; expires=' + expire + ';';"); |
| 45 std::wstring cookie_script2(kExpire); | 150 std::wstring cookie_script2(kExpire); |
| 46 cookie_script2.append( | 151 cookie_script2.append( |
| 47 L"document.cookie = 'guest2=true; path=/; expires=' + expire + ';';"); | 152 L"document.cookie = 'guest2=true; path=/; expires=' + expire + ';';"); |
| 48 | 153 |
| 49 GURL::Replacements replace_host; | 154 GURL::Replacements replace_host; |
| 50 std::string host_str("localhost"); // Must stay in scope with replace_host. | 155 std::string host_str("localhost"); // Must stay in scope with replace_host. |
| 51 replace_host.SetHostStr(host_str); | 156 replace_host.SetHostStr(host_str); |
| 52 | 157 |
| 53 GURL set_cookie_url = test_server()->GetURL( | 158 GURL set_cookie_url = test_server()->GetURL( |
| 54 "files/extensions/platform_apps/isolation/set_cookie.html"); | 159 "files/extensions/platform_apps/isolation/set_cookie.html"); |
| 55 set_cookie_url = set_cookie_url.ReplaceComponents(replace_host); | 160 set_cookie_url = set_cookie_url.ReplaceComponents(replace_host); |
| 56 GURL tag_url1 = test_server()->GetURL( | |
| 57 "files/extensions/platform_apps/web_view_isolation/cookie.html"); | |
| 58 tag_url1 = tag_url1.ReplaceComponents(replace_host); | |
| 59 GURL tag_url2 = test_server()->GetURL( | |
| 60 "files/extensions/platform_apps/web_view_isolation/cookie2.html"); | |
| 61 tag_url2 = tag_url2.ReplaceComponents(replace_host); | |
| 62 | 161 |
| 63 // Load a (non-app) page under the "localhost" origin that sets a cookie. | 162 content::WebContents* contents1; |
| 64 ui_test_utils::NavigateToURLWithDisposition( | 163 content::WebContents* contents2; |
| 65 browser(), set_cookie_url, | 164 content::WebContents* contents3; |
| 66 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 165 content::WebContents* contents4; |
| 67 // Make sure the cookie is set. | 166 |
| 167 NavigateAndOpenAppForIsolation(set_cookie_url, &contents1, &contents2, | |
| 168 &contents3, &contents4); | |
| 169 | |
| 170 EXPECT_TRUE(content::ExecuteJavaScript( | |
| 171 contents1->GetRenderViewHost(), std::wstring(), cookie_script1)); | |
| 172 EXPECT_TRUE(content::ExecuteJavaScript( | |
| 173 contents2->GetRenderViewHost(), std::wstring(), cookie_script2)); | |
| 174 | |
| 68 int cookie_size; | 175 int cookie_size; |
| 69 std::string cookie_value; | 176 std::string cookie_value; |
| 70 automation_util::GetCookies(set_cookie_url, | |
| 71 chrome::GetWebContentsAt(browser(), 0), | |
| 72 &cookie_size, &cookie_value); | |
| 73 EXPECT_EQ("testCookie=1", cookie_value); | |
| 74 | 177 |
| 75 ui_test_utils::UrlLoadObserver observer1( | 178 // Test the regular browser context to ensure we have only one cookie. |
| 76 tag_url1, content::NotificationService::AllSources()); | |
| 77 ui_test_utils::UrlLoadObserver observer2( | |
| 78 tag_url2, content::NotificationService::AllSources()); | |
| 79 LoadAndLaunchPlatformApp("web_view_isolation"); | |
| 80 observer1.Wait(); | |
| 81 observer2.Wait(); | |
| 82 | |
| 83 content::Source<content::NavigationController> source1 = observer1.source(); | |
| 84 EXPECT_TRUE(source1->GetWebContents()->GetRenderProcessHost()->IsGuest()); | |
| 85 content::Source<content::NavigationController> source2 = observer2.source(); | |
| 86 EXPECT_TRUE(source2->GetWebContents()->GetRenderProcessHost()->IsGuest()); | |
| 87 EXPECT_NE(source1->GetWebContents()->GetRenderProcessHost()->GetID(), | |
| 88 source2->GetWebContents()->GetRenderProcessHost()->GetID()); | |
| 89 | |
| 90 EXPECT_TRUE(content::ExecuteJavaScript( | |
| 91 source1->GetWebContents()->GetRenderViewHost(), std::wstring(), | |
| 92 cookie_script1)); | |
| 93 EXPECT_TRUE(content::ExecuteJavaScript( | |
| 94 source2->GetWebContents()->GetRenderViewHost(), std::wstring(), | |
| 95 cookie_script2)); | |
| 96 | |
| 97 // Test the regular browser context to ensure we still have only one cookie. | |
| 98 automation_util::GetCookies(GURL("http://localhost"), | 179 automation_util::GetCookies(GURL("http://localhost"), |
| 99 chrome::GetWebContentsAt(browser(), 0), | 180 chrome::GetWebContentsAt(browser(), 0), |
| 100 &cookie_size, &cookie_value); | 181 &cookie_size, &cookie_value); |
| 101 EXPECT_EQ("testCookie=1", cookie_value); | 182 EXPECT_EQ("testCookie=1", cookie_value); |
| 102 | 183 |
| 103 // The default behavior is to combine webview tags with no explicit partition | 184 // The default behavior is to combine webview tags with no explicit partition |
| 104 // declaration into the same in-memory partition. Test the webview tags to | 185 // declaration into the same in-memory partition. Test the webview tags to |
| 105 // ensure we have properly set the cookies and we have both cookies in both | 186 // ensure we have properly set the cookies and we have both cookies in both |
| 106 // tags. | 187 // tags. |
| 107 automation_util::GetCookies(GURL("http://localhost"), | 188 automation_util::GetCookies(GURL("http://localhost"), |
| 108 source1->GetWebContents(), | 189 contents1, |
| 109 &cookie_size, &cookie_value); | 190 &cookie_size, &cookie_value); |
| 110 EXPECT_EQ("guest1=true; guest2=true", cookie_value); | 191 EXPECT_EQ("guest1=true; guest2=true", cookie_value); |
| 111 | 192 |
| 112 automation_util::GetCookies(GURL("http://localhost"), | 193 automation_util::GetCookies(GURL("http://localhost"), |
| 113 source2->GetWebContents(), | 194 contents2, |
| 114 &cookie_size, &cookie_value); | 195 &cookie_size, &cookie_value); |
| 115 EXPECT_EQ("guest1=true; guest2=true", cookie_value); | 196 EXPECT_EQ("guest1=true; guest2=true", cookie_value); |
| 197 | |
| 198 // The third tag should not have any cookies as it is in separate partition. | |
| 199 automation_util::GetCookies(GURL("http://localhost"), | |
| 200 contents3, | |
| 201 &cookie_size, &cookie_value); | |
| 202 EXPECT_EQ("", cookie_value); | |
| 203 | |
| 116 CloseShellWindowsAndWaitForAppToExit(); | 204 CloseShellWindowsAndWaitForAppToExit(); |
| 117 } | 205 } |
| 206 | |
| 207 // This tests DOM storage isolation for packaged apps with webview tags. It | |
| 208 // loads an app with multiple webview tags and each tag sets DOM storage | |
| 209 // entries, which the test checks to ensure proper storage isolation is | |
| 210 // enforced. | |
| 211 IN_PROC_BROWSER_TEST_F(WebViewTest, DOMStorageIsolation) { | |
| 212 ASSERT_TRUE(StartTestServer()); | |
| 213 GURL regular_url = test_server()->GetURL("files/title1.html"); | |
| 214 | |
| 215 std::string output; | |
| 216 std::wstring get_local_storage(L"window.domAutomationController.send(" | |
| 217 L"window.localStorage.getItem('foo') || 'badval')"); | |
| 218 std::wstring get_session_storage(L"window.domAutomationController.send(" | |
| 219 L"window.sessionStorage.getItem('foo') || 'badval')"); | |
| 220 | |
| 221 content::WebContents* contents1; | |
| 222 content::WebContents* contents2; | |
| 223 content::WebContents* storage_contents1; | |
| 224 content::WebContents* storage_contents2; | |
| 225 | |
| 226 NavigateAndOpenAppForIsolation(regular_url, &contents1, &contents2, | |
| 227 &storage_contents1, &storage_contents2); | |
| 228 | |
| 229 // Initialize the storage for the first of the two tags that share a storage | |
| 230 // partition. | |
| 231 EXPECT_TRUE(content::ExecuteJavaScript( | |
| 232 storage_contents1->GetRenderViewHost(), std::wstring(), | |
| 233 L"initDomStorage('page1')")); | |
| 234 | |
| 235 // Let's test that the expected values are present in the first tag, as they | |
| 236 // will be overwritten once we call the initDomStorage on the second tag. | |
| 237 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( | |
| 238 storage_contents1->GetRenderViewHost(), std::wstring(), | |
| 239 get_local_storage.c_str(), &output)); | |
| 240 EXPECT_STREQ("local-page1", output.c_str()); | |
| 241 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( | |
| 242 storage_contents1->GetRenderViewHost(), std::wstring(), | |
| 243 get_session_storage.c_str(), &output)); | |
| 244 EXPECT_STREQ("session-page1", output.c_str()); | |
| 245 | |
| 246 // Now, init the storage in the second tag in the same storage partition, | |
| 247 // which will overwrite the shared localStorage. | |
| 248 EXPECT_TRUE(content::ExecuteJavaScript( | |
| 249 storage_contents2->GetRenderViewHost(), std::wstring(), | |
| 250 L"initDomStorage('page2')")); | |
| 251 | |
| 252 // The localStorage value now should reflect the one written through the | |
| 253 // second tag. | |
| 254 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( | |
| 255 storage_contents1->GetRenderViewHost(), std::wstring(), | |
| 256 get_local_storage.c_str(), &output)); | |
| 257 EXPECT_STREQ("local-page2", output.c_str()); | |
| 258 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( | |
| 259 storage_contents2->GetRenderViewHost(), std::wstring(), | |
| 260 get_local_storage.c_str(), &output)); | |
| 261 EXPECT_STREQ("local-page2", output.c_str()); | |
| 262 | |
| 263 // Session storage is not shared though, as each webview tag has separate | |
| 264 // instance, even if they are in the same storage partition. | |
| 265 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( | |
| 266 storage_contents1->GetRenderViewHost(), std::wstring(), | |
| 267 get_session_storage.c_str(), &output)); | |
| 268 EXPECT_STREQ("session-page1", output.c_str()); | |
| 269 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( | |
| 270 storage_contents2->GetRenderViewHost(), std::wstring(), | |
| 271 get_session_storage.c_str(), &output)); | |
| 272 EXPECT_STREQ("session-page2", output.c_str()); | |
| 273 | |
| 274 // Also, let's check that the main browser and another tag that doesn't share | |
| 275 // the same partition don't have those values stored. | |
| 276 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( | |
| 277 chrome::GetWebContentsAt(browser(), 0)->GetRenderViewHost(), | |
| 278 std::wstring(), get_local_storage.c_str(), &output)); | |
| 279 EXPECT_STREQ("badval", output.c_str()); | |
| 280 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( | |
| 281 chrome::GetWebContentsAt(browser(), 0)->GetRenderViewHost(), | |
| 282 std::wstring(), get_session_storage.c_str(), &output)); | |
| 283 EXPECT_STREQ("badval", output.c_str()); | |
| 284 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( | |
| 285 contents1->GetRenderViewHost(), std::wstring(), | |
| 286 get_local_storage.c_str(), &output)); | |
| 287 EXPECT_STREQ("badval", output.c_str()); | |
| 288 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( | |
| 289 contents1->GetRenderViewHost(), std::wstring(), | |
| 290 get_session_storage.c_str(), &output)); | |
| 291 EXPECT_STREQ("badval", output.c_str()); | |
| 292 | |
| 293 CloseShellWindowsAndWaitForAppToExit(); | |
| 294 } | |
| 295 | |
| 296 // This tests IndexedDB isolation for packaged apps with webview tags. It loads | |
| 297 // an app with multiple webview tags and each tag creates an IndexedDB record, | |
| 298 // which the test checks to ensure proper storage isolation is enforced. | |
| 299 IN_PROC_BROWSER_TEST_F(WebViewTest, IndexedDBIsolation) { | |
| 300 ASSERT_TRUE(StartTestServer()); | |
| 301 GURL regular_url = test_server()->GetURL("files/title1.html"); | |
| 302 | |
| 303 content::WebContents* contents1; | |
| 304 content::WebContents* contents2; | |
| 305 content::WebContents* storage_contents1; | |
| 306 content::WebContents* storage_contents2; | |
| 307 | |
| 308 NavigateAndOpenAppForIsolation(regular_url, &contents1, &contents2, | |
| 309 &storage_contents1, &storage_contents2); | |
| 310 | |
| 311 // Initialize the storage for the first of the two tags that share a storage | |
| 312 // partition. | |
| 313 ExecuteScriptWaitForTitle(storage_contents1, "initIDB()", "idb created"); | |
| 314 ExecuteScriptWaitForTitle(storage_contents1, "addItemIDB(7, 'page1')", | |
| 315 "addItemIDB complete"); | |
| 316 ExecuteScriptWaitForTitle(storage_contents1, "readItemIDB(7)", | |
| 317 "readItemIDB complete"); | |
| 318 | |
| 319 std::string output; | |
| 320 std::wstring get_value( | |
| 321 L"window.domAutomationController.send(getValueIDB() || 'badval')"); | |
| 322 | |
| 323 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( | |
| 324 storage_contents1->GetRenderViewHost(), std::wstring(), | |
| 325 get_value.c_str(), &output)); | |
| 326 EXPECT_STREQ("page1", output.c_str()); | |
| 327 | |
| 328 // Initialize the db in the second tag. | |
| 329 ExecuteScriptWaitForTitle(storage_contents2, "initIDB()", "idb open"); | |
| 330 | |
| 331 // Since we share a partition, reading the value should return the existing | |
| 332 // one. | |
| 333 ExecuteScriptWaitForTitle(storage_contents2, "readItemIDB(7)", | |
| 334 "readItemIDB complete"); | |
| 335 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( | |
| 336 storage_contents2->GetRenderViewHost(), std::wstring(), | |
| 337 get_value.c_str(), &output)); | |
| 338 EXPECT_STREQ("page1", output.c_str()); | |
| 339 | |
| 340 // Now write through the second tag and read it back. | |
| 341 ExecuteScriptWaitForTitle(storage_contents2, "addItemIDB(7, 'page2')", | |
| 342 "addItemIDB complete"); | |
| 343 ExecuteScriptWaitForTitle(storage_contents2, "readItemIDB(7)", | |
| 344 "readItemIDB complete"); | |
| 345 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( | |
| 346 storage_contents2->GetRenderViewHost(), std::wstring(), | |
| 347 get_value.c_str(), &output)); | |
| 348 EXPECT_STREQ("page2", output.c_str()); | |
| 349 | |
| 350 // Reset the document title, otherwise the next call will not see a change and | |
| 351 // will hang waiting for it. | |
| 352 EXPECT_TRUE(content::ExecuteJavaScript( | |
| 353 storage_contents1->GetRenderViewHost(), std::wstring(), | |
| 354 L"document.title = 'foo'")); | |
| 355 | |
| 356 // Read through the first tag to ensure we have the second value. | |
| 357 ExecuteScriptWaitForTitle(storage_contents1, "readItemIDB(7)", | |
| 358 "readItemIDB complete"); | |
| 359 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( | |
| 360 storage_contents1->GetRenderViewHost(), std::wstring(), | |
| 361 get_value.c_str(), &output)); | |
| 362 EXPECT_STREQ("page2", output.c_str()); | |
| 363 | |
| 364 // Now, let's confirm there is no database in the main browser and another | |
| 365 // tag that doesn't share the same partition. Due to the IndexedDB API design, | |
| 366 // open will succeed, but the version will be 1, since it creates the database | |
| 367 // if it is not found. The two tags use database version 3, so we avoid | |
| 368 // ambiguity. | |
| 369 const char* script = | |
| 370 "indexedDB.open('isolation').onsuccess = function(e) {" | |
| 371 " if (e.target.result.version == 1)" | |
| 372 " document.title = 'db not found';" | |
| 373 " else " | |
| 374 " document.title = 'error';" | |
| 375 "}"; | |
| 376 ExecuteScriptWaitForTitle(chrome::GetWebContentsAt(browser(), 0), | |
| 377 script, "db not found"); | |
| 378 ExecuteScriptWaitForTitle(contents1, script, "db not found"); | |
| 379 | |
| 380 CloseShellWindowsAndWaitForAppToExit(); | |
| 381 } | |
| OLD | NEW |