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

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

Issue 9473001: Extract minimal RenderViewHost interface for embedders, leaving (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to LKGR. Created 8 years, 9 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/extensions/extension_apitest.h" 6 #include "chrome/browser/extensions/extension_apitest.h"
7 #include "chrome/browser/extensions/extension_host.h" 7 #include "chrome/browser/extensions/extension_host.h"
8 #include "chrome/browser/extensions/extension_service.h" 8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/extensions/process_map.h" 9 #include "chrome/browser/extensions/process_map.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 // The above window.open call is not user-initiated, it will create 42 // The above window.open call is not user-initiated, it will create
43 // a popup window instead of a new tab in current window. 43 // a popup window instead of a new tab in current window.
44 // Now the active tab in last active window should be the new tab. 44 // Now the active tab in last active window should be the new tab.
45 Browser* last_active_browser = BrowserList::GetLastActive(); 45 Browser* last_active_browser = BrowserList::GetLastActive();
46 EXPECT_TRUE(last_active_browser); 46 EXPECT_TRUE(last_active_browser);
47 WebContents* newtab = last_active_browser->GetSelectedWebContents(); 47 WebContents* newtab = last_active_browser->GetSelectedWebContents();
48 EXPECT_TRUE(newtab); 48 EXPECT_TRUE(newtab);
49 observer.Wait(); 49 observer.Wait();
50 EXPECT_EQ(url, newtab->GetController().GetLastCommittedEntry()->GetURL()); 50 EXPECT_EQ(url, newtab->GetController().GetLastCommittedEntry()->GetURL());
51 if (newtab_process_should_equal_opener) 51 if (newtab_process_should_equal_opener)
52 EXPECT_EQ(opener_host->process(), newtab->GetRenderProcessHost()); 52 EXPECT_EQ(opener_host->GetProcess(), newtab->GetRenderProcessHost());
53 else 53 else
54 EXPECT_NE(opener_host->process(), newtab->GetRenderProcessHost()); 54 EXPECT_NE(opener_host->GetProcess(), newtab->GetRenderProcessHost());
55 } 55 }
56 56
57 // Simulates a page navigating itself to an URL, and waits for the navigation. 57 // Simulates a page navigating itself to an URL, and waits for the navigation.
58 static void NavigateTabHelper(WebContents* contents, const GURL& url) { 58 static void NavigateTabHelper(WebContents* contents, const GURL& url) {
59 bool result = false; 59 bool result = false;
60 ui_test_utils::WindowedNotificationObserver observer( 60 ui_test_utils::WindowedNotificationObserver observer(
61 content::NOTIFICATION_LOAD_STOP, 61 content::NOTIFICATION_LOAD_STOP,
62 content::NotificationService::AllSources()); 62 content::NotificationService::AllSources());
63 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 63 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
64 contents->GetRenderViewHost(), L"", 64 contents->GetRenderViewHost(), L"",
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 browser()->GetWebContentsAt(2)->GetRenderProcessHost()->GetID())); 137 browser()->GetWebContentsAt(2)->GetRenderProcessHost()->GetID()));
138 EXPECT_FALSE(browser()->GetWebContentsAt(2)->GetWebUI()); 138 EXPECT_FALSE(browser()->GetWebContentsAt(2)->GetWebUI());
139 139
140 // We should have opened 2 new extension tabs. Including the original blank 140 // We should have opened 2 new extension tabs. Including the original blank
141 // tab, we now have 3 tabs. The two app tabs should not be in the same 141 // tab, we now have 3 tabs. The two app tabs should not be in the same
142 // process, since they do not have the background permission. (Thus, we 142 // process, since they do not have the background permission. (Thus, we
143 // want to separate them to improve responsiveness.) 143 // want to separate them to improve responsiveness.)
144 ASSERT_EQ(3, browser()->tab_count()); 144 ASSERT_EQ(3, browser()->tab_count());
145 RenderViewHost* host1 = browser()->GetWebContentsAt(1)->GetRenderViewHost(); 145 RenderViewHost* host1 = browser()->GetWebContentsAt(1)->GetRenderViewHost();
146 RenderViewHost* host2 = browser()->GetWebContentsAt(2)->GetRenderViewHost(); 146 RenderViewHost* host2 = browser()->GetWebContentsAt(2)->GetRenderViewHost();
147 EXPECT_NE(host1->process(), host2->process()); 147 EXPECT_NE(host1->GetProcess(), host2->GetProcess());
148 148
149 // Opening tabs with window.open should keep the page in the opener's 149 // Opening tabs with window.open should keep the page in the opener's
150 // process. 150 // process.
151 ASSERT_EQ(1u, BrowserList::GetBrowserCount(browser()->profile())); 151 ASSERT_EQ(1u, BrowserList::GetBrowserCount(browser()->profile()));
152 WindowOpenHelper(browser(), host1, 152 WindowOpenHelper(browser(), host1,
153 base_url.Resolve("path1/empty.html"), true); 153 base_url.Resolve("path1/empty.html"), true);
154 LOG(INFO) << "WindowOpenHelper 1."; 154 LOG(INFO) << "WindowOpenHelper 1.";
155 WindowOpenHelper(browser(), host2, 155 WindowOpenHelper(browser(), host2,
156 base_url.Resolve("path2/empty.html"), true); 156 base_url.Resolve("path2/empty.html"), true);
157 LOG(INFO) << "End of test."; 157 LOG(INFO) << "End of test.";
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 browser()->GetWebContentsAt(3)->GetRenderProcessHost()->GetID())); 207 browser()->GetWebContentsAt(3)->GetRenderProcessHost()->GetID()));
208 EXPECT_FALSE(browser()->GetWebContentsAt(3)->GetWebUI()); 208 EXPECT_FALSE(browser()->GetWebContentsAt(3)->GetWebUI());
209 209
210 // We should have opened 3 new extension tabs. Including the original blank 210 // We should have opened 3 new extension tabs. Including the original blank
211 // tab, we now have 4 tabs. Because the app_process app has the background 211 // tab, we now have 4 tabs. Because the app_process app has the background
212 // permission, all of its instances are in the same process. Thus two tabs 212 // permission, all of its instances are in the same process. Thus two tabs
213 // should be part of the extension app and grouped in the same process. 213 // should be part of the extension app and grouped in the same process.
214 ASSERT_EQ(4, browser()->tab_count()); 214 ASSERT_EQ(4, browser()->tab_count());
215 RenderViewHost* host = browser()->GetWebContentsAt(1)->GetRenderViewHost(); 215 RenderViewHost* host = browser()->GetWebContentsAt(1)->GetRenderViewHost();
216 216
217 EXPECT_EQ(host->process(), 217 EXPECT_EQ(host->GetProcess(),
218 browser()->GetWebContentsAt(2)->GetRenderProcessHost()); 218 browser()->GetWebContentsAt(2)->GetRenderProcessHost());
219 EXPECT_NE(host->process(), 219 EXPECT_NE(host->GetProcess(),
220 browser()->GetWebContentsAt(3)->GetRenderProcessHost()); 220 browser()->GetWebContentsAt(3)->GetRenderProcessHost());
221 221
222 // Now let's do the same using window.open. The same should happen. 222 // Now let's do the same using window.open. The same should happen.
223 ASSERT_EQ(1u, BrowserList::GetBrowserCount(browser()->profile())); 223 ASSERT_EQ(1u, BrowserList::GetBrowserCount(browser()->profile()));
224 WindowOpenHelper(browser(), host, 224 WindowOpenHelper(browser(), host,
225 base_url.Resolve("path1/empty.html"), true); 225 base_url.Resolve("path1/empty.html"), true);
226 LOG(INFO) << "WindowOpenHelper 1."; 226 LOG(INFO) << "WindowOpenHelper 1.";
227 WindowOpenHelper(browser(), host, 227 WindowOpenHelper(browser(), host,
228 base_url.Resolve("path2/empty.html"), true); 228 base_url.Resolve("path2/empty.html"), true);
229 LOG(INFO) << "WindowOpenHelper 2."; 229 LOG(INFO) << "WindowOpenHelper 2.";
230 // TODO(creis): This should open in a new process (i.e., false for the last 230 // TODO(creis): This should open in a new process (i.e., false for the last
231 // argument), but we temporarily avoid swapping processes away from an app 231 // argument), but we temporarily avoid swapping processes away from an app
232 // until we're able to support cross-process postMessage calls. 232 // until we're able to support cross-process postMessage calls.
233 // See crbug.com/59285. 233 // See crbug.com/59285.
234 WindowOpenHelper(browser(), host, 234 WindowOpenHelper(browser(), host,
235 base_url.Resolve("path3/empty.html"), true); 235 base_url.Resolve("path3/empty.html"), true);
236 LOG(INFO) << "WindowOpenHelper 3."; 236 LOG(INFO) << "WindowOpenHelper 3.";
237 237
238 // Now let's have these pages navigate, into or out of the extension web 238 // Now let's have these pages navigate, into or out of the extension web
239 // extent. They should switch processes. 239 // extent. They should switch processes.
240 const GURL& app_url(base_url.Resolve("path1/empty.html")); 240 const GURL& app_url(base_url.Resolve("path1/empty.html"));
241 const GURL& non_app_url(base_url.Resolve("path3/empty.html")); 241 const GURL& non_app_url(base_url.Resolve("path3/empty.html"));
242 NavigateTabHelper(browser()->GetWebContentsAt(2), non_app_url); 242 NavigateTabHelper(browser()->GetWebContentsAt(2), non_app_url);
243 LOG(INFO) << "NavigateTabHelper 1."; 243 LOG(INFO) << "NavigateTabHelper 1.";
244 NavigateTabHelper(browser()->GetWebContentsAt(3), app_url); 244 NavigateTabHelper(browser()->GetWebContentsAt(3), app_url);
245 LOG(INFO) << "NavigateTabHelper 2."; 245 LOG(INFO) << "NavigateTabHelper 2.";
246 // TODO(creis): This should swap out of the app's process (i.e., EXPECT_NE), 246 // TODO(creis): This should swap out of the app's process (i.e., EXPECT_NE),
247 // but we temporarily avoid swapping away from an app in case the window 247 // but we temporarily avoid swapping away from an app in case the window
248 // tries to send a postMessage to the app. See crbug.com/59285. 248 // tries to send a postMessage to the app. See crbug.com/59285.
249 EXPECT_EQ(host->process(), 249 EXPECT_EQ(host->GetProcess(),
250 browser()->GetWebContentsAt(2)->GetRenderProcessHost()); 250 browser()->GetWebContentsAt(2)->GetRenderProcessHost());
251 EXPECT_EQ(host->process(), 251 EXPECT_EQ(host->GetProcess(),
252 browser()->GetWebContentsAt(3)->GetRenderProcessHost()); 252 browser()->GetWebContentsAt(3)->GetRenderProcessHost());
253 253
254 // If one of the popup tabs navigates back to the app, window.opener should 254 // If one of the popup tabs navigates back to the app, window.opener should
255 // be valid. 255 // be valid.
256 NavigateTabHelper(browser()->GetWebContentsAt(6), app_url); 256 NavigateTabHelper(browser()->GetWebContentsAt(6), app_url);
257 LOG(INFO) << "NavigateTabHelper 3."; 257 LOG(INFO) << "NavigateTabHelper 3.";
258 EXPECT_EQ(host->process(), 258 EXPECT_EQ(host->GetProcess(),
259 browser()->GetWebContentsAt(6)->GetRenderProcessHost()); 259 browser()->GetWebContentsAt(6)->GetRenderProcessHost());
260 bool windowOpenerValid = false; 260 bool windowOpenerValid = false;
261 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 261 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
262 browser()->GetWebContentsAt(6)->GetRenderViewHost(), L"", 262 browser()->GetWebContentsAt(6)->GetRenderViewHost(), L"",
263 L"window.domAutomationController.send(window.opener != null)", 263 L"window.domAutomationController.send(window.opener != null)",
264 &windowOpenerValid)); 264 &windowOpenerValid));
265 ASSERT_TRUE(windowOpenerValid); 265 ASSERT_TRUE(windowOpenerValid);
266 266
267 LOG(INFO) << "End of test."; 267 LOG(INFO) << "End of test.";
268 } 268 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html")); 320 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html"));
321 EXPECT_FALSE(process_map->Contains( 321 EXPECT_FALSE(process_map->Contains(
322 browser()->GetWebContentsAt(2)->GetRenderProcessHost()->GetID())); 322 browser()->GetWebContentsAt(2)->GetRenderProcessHost()->GetID()));
323 EXPECT_FALSE(browser()->GetWebContentsAt(2)->GetWebUI()); 323 EXPECT_FALSE(browser()->GetWebContentsAt(2)->GetWebUI());
324 324
325 // We should have opened 2 new bookmark app tabs. Including the original blank 325 // We should have opened 2 new bookmark app tabs. Including the original blank
326 // tab, we now have 3 tabs. Because normal pages use the 326 // tab, we now have 3 tabs. Because normal pages use the
327 // process-per-site-instance model, each should be in its own process. 327 // process-per-site-instance model, each should be in its own process.
328 ASSERT_EQ(3, browser()->tab_count()); 328 ASSERT_EQ(3, browser()->tab_count());
329 RenderViewHost* host = browser()->GetWebContentsAt(1)->GetRenderViewHost(); 329 RenderViewHost* host = browser()->GetWebContentsAt(1)->GetRenderViewHost();
330 EXPECT_NE(host->process(), 330 EXPECT_NE(host->GetProcess(),
331 browser()->GetWebContentsAt(2)->GetRenderProcessHost()); 331 browser()->GetWebContentsAt(2)->GetRenderProcessHost());
332 332
333 // Now let's do the same using window.open. The same should happen. 333 // Now let's do the same using window.open. The same should happen.
334 ASSERT_EQ(1u, BrowserList::GetBrowserCount(browser()->profile())); 334 ASSERT_EQ(1u, BrowserList::GetBrowserCount(browser()->profile()));
335 WindowOpenHelper(browser(), host, 335 WindowOpenHelper(browser(), host,
336 base_url.Resolve("path1/empty.html"), true); 336 base_url.Resolve("path1/empty.html"), true);
337 WindowOpenHelper(browser(), host, 337 WindowOpenHelper(browser(), host,
338 base_url.Resolve("path2/empty.html"), true); 338 base_url.Resolve("path2/empty.html"), true);
339 339
340 // Now let's have a tab navigate out of and back into the app's web 340 // Now let's have a tab navigate out of and back into the app's web
341 // extent. Neither navigation should switch processes. 341 // extent. Neither navigation should switch processes.
342 const GURL& app_url(base_url.Resolve("path1/empty.html")); 342 const GURL& app_url(base_url.Resolve("path1/empty.html"));
343 const GURL& non_app_url(base_url.Resolve("path3/empty.html")); 343 const GURL& non_app_url(base_url.Resolve("path3/empty.html"));
344 RenderViewHost* host2 = browser()->GetWebContentsAt(2)->GetRenderViewHost(); 344 RenderViewHost* host2 = browser()->GetWebContentsAt(2)->GetRenderViewHost();
345 NavigateTabHelper(browser()->GetWebContentsAt(2), non_app_url); 345 NavigateTabHelper(browser()->GetWebContentsAt(2), non_app_url);
346 EXPECT_EQ(host2->process(), 346 EXPECT_EQ(host2->GetProcess(),
347 browser()->GetWebContentsAt(2)->GetRenderProcessHost()); 347 browser()->GetWebContentsAt(2)->GetRenderProcessHost());
348 NavigateTabHelper(browser()->GetWebContentsAt(2), app_url); 348 NavigateTabHelper(browser()->GetWebContentsAt(2), app_url);
349 EXPECT_EQ(host2->process(), 349 EXPECT_EQ(host2->GetProcess(),
350 browser()->GetWebContentsAt(2)->GetRenderProcessHost()); 350 browser()->GetWebContentsAt(2)->GetRenderProcessHost());
351 } 351 }
352 352
353 // Tests that app process switching works properly in the following scenario: 353 // Tests that app process switching works properly in the following scenario:
354 // 1. navigate to a page1 in the app 354 // 1. navigate to a page1 in the app
355 // 2. page1 redirects to a page2 outside the app extent (ie, "/server-redirect") 355 // 2. page1 redirects to a page2 outside the app extent (ie, "/server-redirect")
356 // 3. page2 redirects back to a page in the app 356 // 3. page2 redirects back to a page in the app
357 // The final navigation should end up in the app process. 357 // The final navigation should end up in the app process.
358 // See http://crbug.com/61757 358 // See http://crbug.com/61757
359 // This test doesn't complete on WebKit Win (dbg). See crbug.com/108853. 359 // This test doesn't complete on WebKit Win (dbg). See crbug.com/108853.
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 &browser()->GetSelectedTabContentsWrapper()->web_contents()-> 664 &browser()->GetSelectedTabContentsWrapper()->web_contents()->
665 GetController())); 665 GetController()));
666 browser()->Reload(CURRENT_TAB); 666 browser()->Reload(CURRENT_TAB);
667 observer.Wait(); 667 observer.Wait();
668 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 668 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
669 contents->GetRenderViewHost(), L"", 669 contents->GetRenderViewHost(), L"",
670 L"window.domAutomationController.send(chrome.app.isInstalled)", 670 L"window.domAutomationController.send(chrome.app.isInstalled)",
671 &is_installed)); 671 &is_installed));
672 ASSERT_TRUE(is_installed); 672 ASSERT_TRUE(is_installed);
673 } 673 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_extension_api.cc ('k') | chrome/browser/extensions/execute_code_in_tab_function.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698