Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Side by Side Diff: chrome/browser/extensions/isolated_app_browsertest.cc

Issue 10795090: Move ExecuteJavaScript functions from ui_test_utils.h to browser_test_utils.h so they can be reused… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/utf_string_conversions.h"
6 #include "chrome/browser/automation/automation_util.h" 6 #include "chrome/browser/automation/automation_util.h"
7 #include "chrome/browser/extensions/extension_apitest.h" 7 #include "chrome/browser/extensions/extension_apitest.h"
8 #include "chrome/browser/extensions/extension_host.h" 8 #include "chrome/browser/extensions/extension_host.h"
9 #include "chrome/browser/extensions/extension_service.h" 9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_commands.h" 12 #include "chrome/browser/ui/browser_commands.h"
13 #include "chrome/browser/ui/browser_tabstrip.h" 13 #include "chrome/browser/ui/browser_tabstrip.h"
14 #include "chrome/browser/ui/tab_contents/tab_contents.h" 14 #include "chrome/browser/ui/tab_contents/tab_contents.h"
15 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/url_constants.h" 16 #include "chrome/common/url_constants.h"
17 #include "chrome/test/base/ui_test_utils.h" 17 #include "chrome/test/base/ui_test_utils.h"
18 #include "content/public/browser/render_process_host.h" 18 #include "content/public/browser/render_process_host.h"
19 #include "content/public/browser/render_view_host.h" 19 #include "content/public/browser/render_view_host.h"
20 #include "content/public/browser/site_instance.h" 20 #include "content/public/browser/site_instance.h"
21 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
22 #include "content/public/test/browser_test_utils.h"
22 #include "net/base/mock_host_resolver.h" 23 #include "net/base/mock_host_resolver.h"
23 24
25 using content::ExecuteJavaScript;
26 using content::ExecuteJavaScriptAndExtractString;
24 using content::NavigationController; 27 using content::NavigationController;
25 using content::WebContents; 28 using content::WebContents;
26 using content::RenderViewHost; 29 using content::RenderViewHost;
27 using ui_test_utils::ExecuteJavaScript;
28 using ui_test_utils::ExecuteJavaScriptAndExtractString;
29 30
30 namespace { 31 namespace {
31 32
32 std::wstring WrapForJavascriptAndExtract( 33 std::wstring WrapForJavascriptAndExtract(
33 const wchar_t* javascript_expression) { 34 const wchar_t* javascript_expression) {
34 return std::wstring(L"window.domAutomationController.send(") + 35 return std::wstring(L"window.domAutomationController.send(") +
35 javascript_expression + L")"; 36 javascript_expression + L")";
36 } 37 }
37 38
38 class IsolatedAppTest : public ExtensionBrowserTest { 39 class IsolatedAppTest : public ExtensionBrowserTest {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 WebContents* tab3 = chrome::GetWebContentsAt(browser(), 2); 114 WebContents* tab3 = chrome::GetWebContentsAt(browser(), 2);
114 ASSERT_TRUE(GetInstalledApp(tab1)); 115 ASSERT_TRUE(GetInstalledApp(tab1));
115 ASSERT_TRUE(GetInstalledApp(tab2)); 116 ASSERT_TRUE(GetInstalledApp(tab2));
116 ASSERT_TRUE(!GetInstalledApp(tab3)); 117 ASSERT_TRUE(!GetInstalledApp(tab3));
117 118
118 // Check that tabs see cannot each other's localStorage even though they are 119 // Check that tabs see cannot each other's localStorage even though they are
119 // in the same origin. 120 // in the same origin.
120 RenderViewHost* app1_rvh = tab1->GetRenderViewHost(); 121 RenderViewHost* app1_rvh = tab1->GetRenderViewHost();
121 RenderViewHost* app2_rvh = tab2->GetRenderViewHost(); 122 RenderViewHost* app2_rvh = tab2->GetRenderViewHost();
122 RenderViewHost* non_app_rvh = tab3->GetRenderViewHost(); 123 RenderViewHost* non_app_rvh = tab3->GetRenderViewHost();
123 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( 124 ASSERT_TRUE(ExecuteJavaScript(
124 app1_rvh, L"", L"window.localStorage.setItem('testdata', 'ls_app1');")); 125 app1_rvh, L"", L"window.localStorage.setItem('testdata', 'ls_app1');"));
125 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( 126 ASSERT_TRUE(ExecuteJavaScript(
126 app2_rvh, L"", L"window.localStorage.setItem('testdata', 'ls_app2');")); 127 app2_rvh, L"", L"window.localStorage.setItem('testdata', 'ls_app2');"));
127 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( 128 ASSERT_TRUE(ExecuteJavaScript(
128 non_app_rvh, L"", 129 non_app_rvh, L"",
129 L"window.localStorage.setItem('testdata', 'ls_normal');")); 130 L"window.localStorage.setItem('testdata', 'ls_normal');"));
130 131
131 ASSERT_TRUE(ExecuteJavaScript( 132 ASSERT_TRUE(ExecuteJavaScript(
132 app1_rvh, L"", L"window.localStorage.getItem('testdata');")); 133 app1_rvh, L"", L"window.localStorage.getItem('testdata');"));
133 134
134 const std::wstring& kRetrieveLocalStorage = 135 const std::wstring& kRetrieveLocalStorage =
135 WrapForJavascriptAndExtract(L"window.localStorage.getItem('testdata')"); 136 WrapForJavascriptAndExtract(L"window.localStorage.getItem('testdata')");
136 std::string result; 137 std::string result;
137 ASSERT_TRUE(ExecuteJavaScriptAndExtractString( 138 ASSERT_TRUE(ExecuteJavaScriptAndExtractString(
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 EXPECT_TRUE(HasCookie(chrome::GetWebContentsAt(browser(), 2), "nonAppFrame=6") ); 221 EXPECT_TRUE(HasCookie(chrome::GetWebContentsAt(browser(), 2), "nonAppFrame=6") );
221 222
222 // Check that all tabs share the same localStorage if they have the same 223 // Check that all tabs share the same localStorage if they have the same
223 // origin. 224 // origin.
224 RenderViewHost* app1_rvh = 225 RenderViewHost* app1_rvh =
225 chrome::GetWebContentsAt(browser(), 0)->GetRenderViewHost(); 226 chrome::GetWebContentsAt(browser(), 0)->GetRenderViewHost();
226 RenderViewHost* app2_rvh = 227 RenderViewHost* app2_rvh =
227 chrome::GetWebContentsAt(browser(), 1)->GetRenderViewHost(); 228 chrome::GetWebContentsAt(browser(), 1)->GetRenderViewHost();
228 RenderViewHost* non_app_rvh = 229 RenderViewHost* non_app_rvh =
229 chrome::GetWebContentsAt(browser(), 2)->GetRenderViewHost(); 230 chrome::GetWebContentsAt(browser(), 2)->GetRenderViewHost();
230 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( 231 ASSERT_TRUE(ExecuteJavaScript(
231 app1_rvh, L"", L"window.localStorage.setItem('testdata', 'ls_app1');")); 232 app1_rvh, L"", L"window.localStorage.setItem('testdata', 'ls_app1');"));
232 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( 233 ASSERT_TRUE(ExecuteJavaScript(
233 app2_rvh, L"", L"window.localStorage.setItem('testdata', 'ls_app2');")); 234 app2_rvh, L"", L"window.localStorage.setItem('testdata', 'ls_app2');"));
234 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( 235 ASSERT_TRUE(ExecuteJavaScript(
235 non_app_rvh, L"", 236 non_app_rvh, L"",
236 L"window.localStorage.setItem('testdata', 'ls_normal');")); 237 L"window.localStorage.setItem('testdata', 'ls_normal');"));
237 238
238 const std::wstring& kRetrieveLocalStorage = 239 const std::wstring& kRetrieveLocalStorage =
239 WrapForJavascriptAndExtract(L"window.localStorage.getItem('testdata')"); 240 WrapForJavascriptAndExtract(L"window.localStorage.getItem('testdata')");
240 std::string result; 241 std::string result;
241 ASSERT_TRUE(ExecuteJavaScriptAndExtractString( 242 ASSERT_TRUE(ExecuteJavaScriptAndExtractString(
242 app1_rvh, L"", kRetrieveLocalStorage.c_str(), &result)); 243 app1_rvh, L"", kRetrieveLocalStorage.c_str(), &result));
243 EXPECT_EQ("ls_normal", result); 244 EXPECT_EQ("ls_normal", result);
244 ASSERT_TRUE(ExecuteJavaScriptAndExtractString( 245 ASSERT_TRUE(ExecuteJavaScriptAndExtractString(
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 chrome::GetWebContentsAt(browser(), 2)->GetRenderProcessHost()->GetI D()); 297 chrome::GetWebContentsAt(browser(), 2)->GetRenderProcessHost()->GetI D());
297 EXPECT_NE(process_id_0, 298 EXPECT_NE(process_id_0,
298 chrome::GetWebContentsAt(browser(), 3)->GetRenderProcessHost()->GetI D()); 299 chrome::GetWebContentsAt(browser(), 3)->GetRenderProcessHost()->GetI D());
299 300
300 // Navigating the second tab out of the app should cause a process swap. 301 // Navigating the second tab out of the app should cause a process swap.
301 const GURL& non_app_url(base_url.Resolve("non_app/main.html")); 302 const GURL& non_app_url(base_url.Resolve("non_app/main.html"));
302 NavigateInRenderer(chrome::GetWebContentsAt(browser(), 1), non_app_url); 303 NavigateInRenderer(chrome::GetWebContentsAt(browser(), 1), non_app_url);
303 EXPECT_NE(process_id_1, 304 EXPECT_NE(process_id_1,
304 chrome::GetWebContentsAt(browser(), 1)->GetRenderProcessHost()->GetI D()); 305 chrome::GetWebContentsAt(browser(), 1)->GetRenderProcessHost()->GetI D());
305 } 306 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_startup_browsertest.cc ('k') | chrome/browser/extensions/lazy_background_page_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698