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

Side by Side Diff: chrome/browser/extensions/app_process_apitest.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 "chrome/browser/extensions/extension_apitest.h" 5 #include "chrome/browser/extensions/extension_apitest.h"
6 #include "chrome/browser/extensions/extension_host.h" 6 #include "chrome/browser/extensions/extension_host.h"
7 #include "chrome/browser/extensions/extension_service.h" 7 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/extensions/process_map.h" 8 #include "chrome/browser/extensions/process_map.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_commands.h" 11 #include "chrome/browser/ui/browser_commands.h"
12 #include "chrome/browser/ui/browser_finder.h" 12 #include "chrome/browser/ui/browser_finder.h"
13 #include "chrome/browser/ui/browser_list.h" 13 #include "chrome/browser/ui/browser_list.h"
14 #include "chrome/browser/ui/browser_tabstrip.h" 14 #include "chrome/browser/ui/browser_tabstrip.h"
15 #include "chrome/browser/ui/browser_window.h" 15 #include "chrome/browser/ui/browser_window.h"
16 #include "chrome/browser/ui/tab_contents/tab_contents.h" 16 #include "chrome/browser/ui/tab_contents/tab_contents.h"
17 #include "chrome/common/chrome_notification_types.h" 17 #include "chrome/common/chrome_notification_types.h"
18 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/extensions/extension.h" 19 #include "chrome/common/extensions/extension.h"
20 #include "chrome/common/extensions/extension_file_util.h" 20 #include "chrome/common/extensions/extension_file_util.h"
21 #include "chrome/common/string_ordinal.h" 21 #include "chrome/common/string_ordinal.h"
22 #include "chrome/test/base/ui_test_utils.h" 22 #include "chrome/test/base/ui_test_utils.h"
23 #include "content/public/browser/navigation_entry.h" 23 #include "content/public/browser/navigation_entry.h"
24 #include "content/public/browser/notification_service.h" 24 #include "content/public/browser/notification_service.h"
25 #include "content/public/browser/render_process_host.h" 25 #include "content/public/browser/render_process_host.h"
26 #include "content/public/browser/render_view_host.h" 26 #include "content/public/browser/render_view_host.h"
27 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
28 #include "content/public/test/browser_test_utils.h"
28 #include "content/public/test/test_navigation_observer.h" 29 #include "content/public/test/test_navigation_observer.h"
29 #include "net/base/mock_host_resolver.h" 30 #include "net/base/mock_host_resolver.h"
30 31
31 using content::NavigationController; 32 using content::NavigationController;
32 using content::RenderViewHost; 33 using content::RenderViewHost;
33 using content::WebContents; 34 using content::WebContents;
34 using extensions::Extension; 35 using extensions::Extension;
35 36
36 class AppApiTest : public ExtensionApiTest { 37 class AppApiTest : public ExtensionApiTest {
37 protected: 38 protected:
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 EXPECT_EQ(tab->GetRenderProcessHost(), 206 EXPECT_EQ(tab->GetRenderProcessHost(),
206 chrome::GetWebContentsAt(browser(), 3)->GetRenderProcessHost()); 207 chrome::GetWebContentsAt(browser(), 3)->GetRenderProcessHost());
207 208
208 // If one of the popup tabs navigates back to the app, window.opener should 209 // If one of the popup tabs navigates back to the app, window.opener should
209 // be valid. 210 // be valid.
210 NavigateInRenderer(chrome::GetWebContentsAt(browser(), 6), app_url); 211 NavigateInRenderer(chrome::GetWebContentsAt(browser(), 6), app_url);
211 LOG(INFO) << "NavigateTabHelper 3."; 212 LOG(INFO) << "NavigateTabHelper 3.";
212 EXPECT_EQ(tab->GetRenderProcessHost(), 213 EXPECT_EQ(tab->GetRenderProcessHost(),
213 chrome::GetWebContentsAt(browser(), 6)->GetRenderProcessHost()); 214 chrome::GetWebContentsAt(browser(), 6)->GetRenderProcessHost());
214 bool windowOpenerValid = false; 215 bool windowOpenerValid = false;
215 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 216 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool(
216 chrome::GetWebContentsAt(browser(), 6)->GetRenderViewHost(), L"", 217 chrome::GetWebContentsAt(browser(), 6)->GetRenderViewHost(), L"",
217 L"window.domAutomationController.send(window.opener != null)", 218 L"window.domAutomationController.send(window.opener != null)",
218 &windowOpenerValid)); 219 &windowOpenerValid));
219 ASSERT_TRUE(windowOpenerValid); 220 ASSERT_TRUE(windowOpenerValid);
220 221
221 LOG(INFO) << "End of test."; 222 LOG(INFO) << "End of test.";
222 } 223 }
223 224
224 // Test that hosted apps without the background permission use a process per app 225 // Test that hosted apps without the background permission use a process per app
225 // instance model, such that separate instances are in separate processes. 226 // instance model, such that separate instances are in separate processes.
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 reload_observer2.Wait(); 406 reload_observer2.Wait();
406 EXPECT_FALSE(process_map->Contains( 407 EXPECT_FALSE(process_map->Contains(
407 contents->GetRenderProcessHost()->GetID())); 408 contents->GetRenderProcessHost()->GetID()));
408 409
409 // Enable app and reload via JavaScript. 410 // Enable app and reload via JavaScript.
410 EnableExtension(app->id()); 411 EnableExtension(app->id());
411 content::WindowedNotificationObserver js_reload_observer( 412 content::WindowedNotificationObserver js_reload_observer(
412 content::NOTIFICATION_LOAD_STOP, 413 content::NOTIFICATION_LOAD_STOP,
413 content::Source<NavigationController>( 414 content::Source<NavigationController>(
414 &chrome::GetActiveWebContents(browser())->GetController())); 415 &chrome::GetActiveWebContents(browser())->GetController()));
415 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(contents->GetRenderViewHost(), 416 ASSERT_TRUE(content::ExecuteJavaScript(contents->GetRenderViewHost(),
416 L"", L"location.reload();")); 417 L"", L"location.reload();"));
417 js_reload_observer.Wait(); 418 js_reload_observer.Wait();
418 EXPECT_TRUE(process_map->Contains( 419 EXPECT_TRUE(process_map->Contains(
419 contents->GetRenderProcessHost()->GetID())); 420 contents->GetRenderProcessHost()->GetID()));
420 421
421 // Disable app and reload via JavaScript. 422 // Disable app and reload via JavaScript.
422 DisableExtension(app->id()); 423 DisableExtension(app->id());
423 content::WindowedNotificationObserver js_reload_observer2( 424 content::WindowedNotificationObserver js_reload_observer2(
424 content::NOTIFICATION_LOAD_STOP, 425 content::NOTIFICATION_LOAD_STOP,
425 content::Source<NavigationController>( 426 content::Source<NavigationController>(
426 &chrome::GetActiveWebContents(browser())->GetController())); 427 &chrome::GetActiveWebContents(browser())->GetController()));
427 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(contents->GetRenderViewHost(), 428 ASSERT_TRUE(content::ExecuteJavaScript(contents->GetRenderViewHost(),
428 L"", L"location = location;")); 429 L"", L"location = location;"));
429 js_reload_observer2.Wait(); 430 js_reload_observer2.Wait();
430 EXPECT_FALSE(process_map->Contains( 431 EXPECT_FALSE(process_map->Contains(
431 contents->GetRenderProcessHost()->GetID())); 432 contents->GetRenderProcessHost()->GetID()));
432 } 433 }
433 434
434 // Tests that if we have a non-app process (path3/container.html) that has an 435 // Tests that if we have a non-app process (path3/container.html) that has an
435 // iframe with a URL in the app's extent (path1/iframe.html), then opening a 436 // iframe with a URL in the app's extent (path1/iframe.html), then opening a
436 // link from that iframe to a new window to a URL in the app's extent (path1/ 437 // link from that iframe to a new window to a URL in the app's extent (path1/
437 // empty.html) results in the new window being in an app process. See 438 // empty.html) results in the new window being in an app process. See
438 // http://crbug.com/89272 for more details. 439 // http://crbug.com/89272 for more details.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 494 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
494 495
495 // Wait for app tab to be created and loaded. 496 // Wait for app tab to be created and loaded.
496 test_navigation_observer.WaitForObservation( 497 test_navigation_observer.WaitForObservation(
497 base::Bind(&ui_test_utils::RunMessageLoop), 498 base::Bind(&ui_test_utils::RunMessageLoop),
498 base::Bind(&MessageLoop::Quit, 499 base::Bind(&MessageLoop::Quit,
499 base::Unretained(MessageLoopForUI::current()))); 500 base::Unretained(MessageLoopForUI::current())));
500 501
501 // App has loaded, and chrome.app.isInstalled should be true. 502 // App has loaded, and chrome.app.isInstalled should be true.
502 bool is_installed = false; 503 bool is_installed = false;
503 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 504 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool(
504 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", 505 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"",
505 L"window.domAutomationController.send(chrome.app.isInstalled)", 506 L"window.domAutomationController.send(chrome.app.isInstalled)",
506 &is_installed)); 507 &is_installed));
507 ASSERT_TRUE(is_installed); 508 ASSERT_TRUE(is_installed);
508 } 509 }
509 510
510 // Tests that if we have an app process (path1/container.html) with a non-app 511 // Tests that if we have an app process (path1/container.html) with a non-app
511 // iframe (path3/iframe.html), then opening a link from that iframe to a new 512 // iframe (path3/iframe.html), then opening a link from that iframe to a new
512 // window to a same-origin non-app URL (path3/empty.html) should keep the window 513 // window to a same-origin non-app URL (path3/empty.html) should keep the window
513 // in the app process. 514 // in the app process.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process"))); 563 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process")));
563 564
564 GURL base_url = GetTestBaseURL("app_process"); 565 GURL base_url = GetTestBaseURL("app_process");
565 566
566 // Load the app, chrome.app.isInstalled should be true. 567 // Load the app, chrome.app.isInstalled should be true.
567 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); 568 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html"));
568 WebContents* contents = chrome::GetWebContentsAt(browser(), 0); 569 WebContents* contents = chrome::GetWebContentsAt(browser(), 0);
569 EXPECT_TRUE(process_map->Contains( 570 EXPECT_TRUE(process_map->Contains(
570 contents->GetRenderProcessHost()->GetID())); 571 contents->GetRenderProcessHost()->GetID()));
571 bool is_installed = false; 572 bool is_installed = false;
572 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 573 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool(
573 contents->GetRenderViewHost(), L"", 574 contents->GetRenderViewHost(), L"",
574 L"window.domAutomationController.send(chrome.app.isInstalled)", 575 L"window.domAutomationController.send(chrome.app.isInstalled)",
575 &is_installed)); 576 &is_installed));
576 ASSERT_TRUE(is_installed); 577 ASSERT_TRUE(is_installed);
577 578
578 // Crash the tab and reload it, chrome.app.isInstalled should still be true. 579 // Crash the tab and reload it, chrome.app.isInstalled should still be true.
579 ui_test_utils::CrashTab(chrome::GetActiveWebContents(browser())); 580 ui_test_utils::CrashTab(chrome::GetActiveWebContents(browser()));
580 content::WindowedNotificationObserver observer( 581 content::WindowedNotificationObserver observer(
581 content::NOTIFICATION_LOAD_STOP, 582 content::NOTIFICATION_LOAD_STOP,
582 content::Source<NavigationController>( 583 content::Source<NavigationController>(
583 &chrome::GetActiveWebContents(browser())->GetController())); 584 &chrome::GetActiveWebContents(browser())->GetController()));
584 chrome::Reload(browser(), CURRENT_TAB); 585 chrome::Reload(browser(), CURRENT_TAB);
585 observer.Wait(); 586 observer.Wait();
586 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 587 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool(
587 contents->GetRenderViewHost(), L"", 588 contents->GetRenderViewHost(), L"",
588 L"window.domAutomationController.send(chrome.app.isInstalled)", 589 L"window.domAutomationController.send(chrome.app.isInstalled)",
589 &is_installed)); 590 &is_installed));
590 ASSERT_TRUE(is_installed); 591 ASSERT_TRUE(is_installed);
591 } 592 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698