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