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

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

Issue 3136019: Fix a few test failures when landing http://trac.webkit.org/changeset/57178.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 4 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
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_browsertests_misc.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/browser.h" 6 #include "chrome/browser/browser.h"
7 #include "chrome/browser/browser_list.h"
7 #include "chrome/browser/extensions/extension_apitest.h" 8 #include "chrome/browser/extensions/extension_apitest.h"
8 #include "chrome/browser/extensions/extension_host.h" 9 #include "chrome/browser/extensions/extension_host.h"
9 #include "chrome/browser/extensions/extension_process_manager.h" 10 #include "chrome/browser/extensions/extension_process_manager.h"
10 #include "chrome/browser/profile.h" 11 #include "chrome/browser/profile.h"
11 #include "chrome/browser/renderer_host/render_view_host.h" 12 #include "chrome/browser/renderer_host/render_view_host.h"
12 #include "chrome/browser/tab_contents/tab_contents.h" 13 #include "chrome/browser/tab_contents/tab_contents.h"
13 #include "chrome/common/chrome_switches.h" 14 #include "chrome/common/chrome_switches.h"
14 #include "chrome/test/ui_test_utils.h" 15 #include "chrome/test/ui_test_utils.h"
15 #include "net/base/mock_host_resolver.h" 16 #include "net/base/mock_host_resolver.h"
16 17
17 class AppApiTest : public ExtensionApiTest { 18 class AppApiTest : public ExtensionApiTest {
18 }; 19 };
19 20
20 // Simulates a page calling window.open on an URL, and waits for the navigation. 21 // Simulates a page calling window.open on an URL, and waits for the navigation.
21 static void WindowOpenHelper(Browser* browser, 22 static void WindowOpenHelper(Browser* browser,
22 RenderViewHost* opener_host, const GURL& url) { 23 RenderViewHost* opener_host,
24 const GURL& url,
25 bool newtab_process_should_equal_opener) {
23 bool result = false; 26 bool result = false;
24 ui_test_utils::ExecuteJavaScriptAndExtractBool( 27 ui_test_utils::ExecuteJavaScriptAndExtractBool(
25 opener_host, L"", 28 opener_host, L"",
26 L"window.open('" + UTF8ToWide(url.spec()) + L"');" 29 L"window.open('" + UTF8ToWide(url.spec()) + L"');"
27 L"window.domAutomationController.send(true);", 30 L"window.domAutomationController.send(true);",
28 &result); 31 &result);
29 ASSERT_TRUE(result); 32 ASSERT_TRUE(result);
30 33
31 // Now the current tab should be the new tab. 34 // The above window.open call is not user-initiated, it will create
32 TabContents* newtab = browser->GetSelectedTabContents(); 35 // a popup window instead of a new tab in current window.
36 // Now the active tab in last active window should be the new tab.
37 Browser* last_active_browser = BrowserList::GetLastActive();
38 EXPECT_TRUE(last_active_browser);
39 TabContents* newtab = last_active_browser->GetSelectedTabContents();
40 EXPECT_TRUE(newtab);
33 if (!newtab->controller().GetLastCommittedEntry() || 41 if (!newtab->controller().GetLastCommittedEntry() ||
34 newtab->controller().GetLastCommittedEntry()->url() != url) 42 newtab->controller().GetLastCommittedEntry()->url() != url)
35 ui_test_utils::WaitForNavigation(&newtab->controller()); 43 ui_test_utils::WaitForNavigation(&newtab->controller());
36 EXPECT_EQ(url, newtab->controller().GetLastCommittedEntry()->url()); 44 EXPECT_EQ(url, newtab->controller().GetLastCommittedEntry()->url());
45 if (newtab_process_should_equal_opener)
46 EXPECT_EQ(opener_host->process(), newtab->render_view_host()->process());
47 else
48 EXPECT_NE(opener_host->process(), newtab->render_view_host()->process());
37 } 49 }
38 50
39 // Simulates a page navigating itself to an URL, and waits for the navigation. 51 // Simulates a page navigating itself to an URL, and waits for the navigation.
40 static void NavigateTabHelper(TabContents* contents, const GURL& url) { 52 static void NavigateTabHelper(TabContents* contents, const GURL& url) {
41 bool result = false; 53 bool result = false;
42 ui_test_utils::ExecuteJavaScriptAndExtractBool( 54 ui_test_utils::ExecuteJavaScriptAndExtractBool(
43 contents->render_view_host(), L"", 55 contents->render_view_host(), L"",
44 L"window.addEventListener('unload', function() {" 56 L"window.addEventListener('unload', function() {"
45 L" window.domAutomationController.send(true);" 57 L" window.domAutomationController.send(true);"
46 L"}, false);" 58 L"}, false);"
47 L"window.location = '" + UTF8ToWide(url.spec()) + L"';", 59 L"window.location = '" + UTF8ToWide(url.spec()) + L"';",
48 &result); 60 &result);
49 ASSERT_TRUE(result); 61 ASSERT_TRUE(result);
50 62
51 if (!contents->controller().GetLastCommittedEntry() || 63 if (!contents->controller().GetLastCommittedEntry() ||
52 contents->controller().GetLastCommittedEntry()->url() != url) 64 contents->controller().GetLastCommittedEntry()->url() != url)
53 ui_test_utils::WaitForNavigation(&contents->controller()); 65 ui_test_utils::WaitForNavigation(&contents->controller());
54 EXPECT_EQ(url, contents->controller().GetLastCommittedEntry()->url()); 66 EXPECT_EQ(url, contents->controller().GetLastCommittedEntry()->url());
55 } 67 }
56 68
57 IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcess) { 69 IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcess) {
70 CommandLine::ForCurrentProcess()->AppendSwitch(
71 switches::kDisablePopupBlocking);
72
58 host_resolver()->AddRule("*", "127.0.0.1"); 73 host_resolver()->AddRule("*", "127.0.0.1");
59 ASSERT_TRUE(test_server()->Start()); 74 ASSERT_TRUE(test_server()->Start());
60 75
61 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process"))); 76 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process")));
62 77
63 // Open two tabs in the app, one outside it. 78 // Open two tabs in the app, one outside it.
64 GURL base_url("http://localhost:1337/files/extensions/api_test/app_process/"); 79 GURL base_url("http://localhost:1337/files/extensions/api_test/app_process/");
65 browser()->NewTab(); 80 browser()->NewTab();
66 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); 81 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html"));
67 browser()->NewTab(); 82 browser()->NewTab();
68 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html")); 83 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html"));
69 browser()->NewTab(); 84 browser()->NewTab();
70 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path3/empty.html")); 85 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path3/empty.html"));
71 86
72 // The extension should have opened 3 new tabs. Including the original blank 87 // The extension should have opened 3 new tabs. Including the original blank
73 // tab, we now have 4 tabs. Two should be part of the extension app, and 88 // tab, we now have 4 tabs. Two should be part of the extension app, and
74 // grouped in the extension process. 89 // grouped in the extension process.
75 ASSERT_EQ(4, browser()->tab_count()); 90 ASSERT_EQ(4, browser()->tab_count());
76 RenderViewHost* host = browser()->GetTabContentsAt(1)->render_view_host(); 91 RenderViewHost* host = browser()->GetTabContentsAt(1)->render_view_host();
77 EXPECT_TRUE(host->is_extension_process()); 92 EXPECT_TRUE(host->is_extension_process());
78 93
79 EXPECT_EQ(host->process(), 94 EXPECT_EQ(host->process(),
80 browser()->GetTabContentsAt(2)->render_view_host()->process()); 95 browser()->GetTabContentsAt(2)->render_view_host()->process());
81 EXPECT_NE(host->process(), 96 EXPECT_NE(host->process(),
82 browser()->GetTabContentsAt(3)->render_view_host()->process()); 97 browser()->GetTabContentsAt(3)->render_view_host()->process());
83 98
84 // Now let's do the same using window.open. The same should happen. 99 // Now let's do the same using window.open. The same should happen.
100 ASSERT_EQ(1u, BrowserList::GetBrowserCount(browser()->profile()));
85 WindowOpenHelper(browser(), host, 101 WindowOpenHelper(browser(), host,
86 base_url.Resolve("path1/empty.html")); 102 base_url.Resolve("path1/empty.html"), true);
87 WindowOpenHelper(browser(), host, 103 WindowOpenHelper(browser(), host,
88 base_url.Resolve("path2/empty.html")); 104 base_url.Resolve("path2/empty.html"), true);
89 WindowOpenHelper(browser(), host, 105 WindowOpenHelper(browser(), host,
90 base_url.Resolve("path3/empty.html")); 106 base_url.Resolve("path3/empty.html"), false);
91
92 ASSERT_EQ(7, browser()->tab_count());
93 EXPECT_EQ(host->process(),
94 browser()->GetTabContentsAt(4)->render_view_host()->process());
95 EXPECT_EQ(host->process(),
96 browser()->GetTabContentsAt(5)->render_view_host()->process());
97 EXPECT_NE(host->process(),
98 browser()->GetTabContentsAt(6)->render_view_host()->process());
99 107
100 // Now let's have these pages navigate, into or out of the extension web 108 // Now let's have these pages navigate, into or out of the extension web
101 // extent. They should switch processes. 109 // extent. They should switch processes.
102 const GURL& app_url(base_url.Resolve("path1/empty.html")); 110 const GURL& app_url(base_url.Resolve("path1/empty.html"));
103 const GURL& non_app_url(base_url.Resolve("path3/empty.html")); 111 const GURL& non_app_url(base_url.Resolve("path3/empty.html"));
104 NavigateTabHelper(browser()->GetTabContentsAt(2), non_app_url); 112 NavigateTabHelper(browser()->GetTabContentsAt(2), non_app_url);
105 NavigateTabHelper(browser()->GetTabContentsAt(3), app_url); 113 NavigateTabHelper(browser()->GetTabContentsAt(3), app_url);
106 EXPECT_NE(host->process(), 114 EXPECT_NE(host->process(),
107 browser()->GetTabContentsAt(2)->render_view_host()->process()); 115 browser()->GetTabContentsAt(2)->render_view_host()->process());
108 EXPECT_EQ(host->process(), 116 EXPECT_EQ(host->process(),
109 browser()->GetTabContentsAt(3)->render_view_host()->process()); 117 browser()->GetTabContentsAt(3)->render_view_host()->process());
110 118
111 // Navigate the non-app tab into the browse extent. It should not enter the 119 // Navigate the non-app tab into the browse extent. It should not enter the
112 // app process. 120 // app process.
113 // Navigate the app tab into the browse extent. It should stay in the app 121 // Navigate the app tab into the browse extent. It should stay in the app
114 // process. 122 // process.
115 const GURL& browse_url(base_url.Resolve("path4/empty.html")); 123 const GURL& browse_url(base_url.Resolve("path4/empty.html"));
116 NavigateTabHelper(browser()->GetTabContentsAt(2), browse_url); 124 NavigateTabHelper(browser()->GetTabContentsAt(2), browse_url);
117 NavigateTabHelper(browser()->GetTabContentsAt(3), browse_url); 125 NavigateTabHelper(browser()->GetTabContentsAt(3), browse_url);
118 EXPECT_NE(host->process(), 126 EXPECT_NE(host->process(),
119 browser()->GetTabContentsAt(2)->render_view_host()->process()); 127 browser()->GetTabContentsAt(2)->render_view_host()->process());
120 EXPECT_EQ(host->process(), 128 EXPECT_EQ(host->process(),
121 browser()->GetTabContentsAt(3)->render_view_host()->process()); 129 browser()->GetTabContentsAt(3)->render_view_host()->process());
122 } 130 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_browsertests_misc.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698