OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_process_manager.h" | 8 #include "chrome/browser/extensions/extension_process_manager.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_list.h" | 11 #include "chrome/browser/ui/browser_list.h" |
12 #include "chrome/browser/ui/browser_window.h" | 12 #include "chrome/browser/ui/browser_window.h" |
13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
15 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
16 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
17 #include "content/browser/renderer_host/render_view_host.h" | 17 #include "content/browser/renderer_host/render_view_host.h" |
18 #include "content/browser/tab_contents/tab_contents.h" | 18 #include "content/browser/tab_contents/tab_contents.h" |
| 19 #include "content/public/browser/notification_service.h" |
19 #include "net/base/mock_host_resolver.h" | 20 #include "net/base/mock_host_resolver.h" |
20 | 21 |
21 class AppApiTest : public ExtensionApiTest { | 22 class AppApiTest : public ExtensionApiTest { |
22 protected: | 23 protected: |
23 // Gets the base URL for files for a specific test, making sure that it uses | 24 // Gets the base URL for files for a specific test, making sure that it uses |
24 // "localhost" as the hostname, since that is what the extent is declared | 25 // "localhost" as the hostname, since that is what the extent is declared |
25 // as in the test apps manifests. | 26 // as in the test apps manifests. |
26 GURL GetTestBaseURL(std::string test_directory) { | 27 GURL GetTestBaseURL(std::string test_directory) { |
27 GURL::Replacements replace_host; | 28 GURL::Replacements replace_host; |
28 std::string host_str("localhost"); // must stay in scope with replace_host | 29 std::string host_str("localhost"); // must stay in scope with replace_host |
29 replace_host.SetHostStr(host_str); | 30 replace_host.SetHostStr(host_str); |
30 GURL base_url = test_server()->GetURL( | 31 GURL base_url = test_server()->GetURL( |
31 "files/extensions/api_test/" + test_directory + "/"); | 32 "files/extensions/api_test/" + test_directory + "/"); |
32 return base_url.ReplaceComponents(replace_host); | 33 return base_url.ReplaceComponents(replace_host); |
33 } | 34 } |
34 }; | 35 }; |
35 | 36 |
36 // Simulates a page calling window.open on an URL, and waits for the navigation. | 37 // Simulates a page calling window.open on an URL, and waits for the navigation. |
37 static void WindowOpenHelper(Browser* browser, | 38 static void WindowOpenHelper(Browser* browser, |
38 RenderViewHost* opener_host, | 39 RenderViewHost* opener_host, |
39 const GURL& url, | 40 const GURL& url, |
40 bool newtab_process_should_equal_opener) { | 41 bool newtab_process_should_equal_opener) { |
41 ui_test_utils::WindowedNotificationObserver observer( | 42 ui_test_utils::WindowedNotificationObserver observer( |
42 content::NOTIFICATION_LOAD_STOP, NotificationService::AllSources()); | 43 content::NOTIFICATION_LOAD_STOP, |
| 44 content::NotificationService::AllSources()); |
43 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( | 45 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( |
44 opener_host, L"", L"window.open('" + UTF8ToWide(url.spec()) + L"');")); | 46 opener_host, L"", L"window.open('" + UTF8ToWide(url.spec()) + L"');")); |
45 | 47 |
46 // The above window.open call is not user-initiated, it will create | 48 // The above window.open call is not user-initiated, it will create |
47 // a popup window instead of a new tab in current window. | 49 // a popup window instead of a new tab in current window. |
48 // Now the active tab in last active window should be the new tab. | 50 // Now the active tab in last active window should be the new tab. |
49 Browser* last_active_browser = BrowserList::GetLastActive(); | 51 Browser* last_active_browser = BrowserList::GetLastActive(); |
50 EXPECT_TRUE(last_active_browser); | 52 EXPECT_TRUE(last_active_browser); |
51 TabContents* newtab = last_active_browser->GetSelectedTabContents(); | 53 TabContents* newtab = last_active_browser->GetSelectedTabContents(); |
52 EXPECT_TRUE(newtab); | 54 EXPECT_TRUE(newtab); |
53 observer.Wait(); | 55 observer.Wait(); |
54 EXPECT_EQ(url, newtab->controller().GetLastCommittedEntry()->url()); | 56 EXPECT_EQ(url, newtab->controller().GetLastCommittedEntry()->url()); |
55 if (newtab_process_should_equal_opener) | 57 if (newtab_process_should_equal_opener) |
56 EXPECT_EQ(opener_host->process(), newtab->render_view_host()->process()); | 58 EXPECT_EQ(opener_host->process(), newtab->render_view_host()->process()); |
57 else | 59 else |
58 EXPECT_NE(opener_host->process(), newtab->render_view_host()->process()); | 60 EXPECT_NE(opener_host->process(), newtab->render_view_host()->process()); |
59 } | 61 } |
60 | 62 |
61 // Simulates a page navigating itself to an URL, and waits for the navigation. | 63 // Simulates a page navigating itself to an URL, and waits for the navigation. |
62 static void NavigateTabHelper(TabContents* contents, const GURL& url) { | 64 static void NavigateTabHelper(TabContents* contents, const GURL& url) { |
63 bool result = false; | 65 bool result = false; |
64 ui_test_utils::WindowedNotificationObserver observer( | 66 ui_test_utils::WindowedNotificationObserver observer( |
65 content::NOTIFICATION_LOAD_STOP, | 67 content::NOTIFICATION_LOAD_STOP, |
66 NotificationService::AllSources()); | 68 content::NotificationService::AllSources()); |
67 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 69 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
68 contents->render_view_host(), L"", | 70 contents->render_view_host(), L"", |
69 L"window.addEventListener('unload', function() {" | 71 L"window.addEventListener('unload', function() {" |
70 L" window.domAutomationController.send(true);" | 72 L" window.domAutomationController.send(true);" |
71 L"}, false);" | 73 L"}, false);" |
72 L"window.location = '" + UTF8ToWide(url.spec()) + L"';", | 74 L"window.location = '" + UTF8ToWide(url.spec()) + L"';", |
73 &result)); | 75 &result)); |
74 ASSERT_TRUE(result); | 76 ASSERT_TRUE(result); |
75 observer.Wait(); | 77 observer.Wait(); |
76 EXPECT_EQ(url, contents->controller().GetLastCommittedEntry()->url()); | 78 EXPECT_EQ(url, contents->controller().GetLastCommittedEntry()->url()); |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 ASSERT_TRUE(test_server()->Start()); | 423 ASSERT_TRUE(test_server()->Start()); |
422 | 424 |
423 GURL base_url = GetTestBaseURL("app_process"); | 425 GURL base_url = GetTestBaseURL("app_process"); |
424 | 426 |
425 // Load app and start URL (in the app). | 427 // Load app and start URL (in the app). |
426 const Extension* app = | 428 const Extension* app = |
427 LoadExtension(test_data_dir_.AppendASCII("app_process")); | 429 LoadExtension(test_data_dir_.AppendASCII("app_process")); |
428 ASSERT_TRUE(app); | 430 ASSERT_TRUE(app); |
429 ui_test_utils::WindowedNotificationObserver observer( | 431 ui_test_utils::WindowedNotificationObserver observer( |
430 content::NOTIFICATION_LOAD_STOP, | 432 content::NOTIFICATION_LOAD_STOP, |
431 NotificationService::AllSources()); | 433 content::NotificationService::AllSources()); |
432 ui_test_utils::NavigateToURLWithDisposition( | 434 ui_test_utils::NavigateToURLWithDisposition( |
433 browser(), | 435 browser(), |
434 base_url.Resolve("path1/container.html"), | 436 base_url.Resolve("path1/container.html"), |
435 CURRENT_TAB, | 437 CURRENT_TAB, |
436 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION | | 438 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION | |
437 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); | 439 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); |
438 RenderProcessHost* process = | 440 RenderProcessHost* process = |
439 browser()->GetTabContentsAt(0)->render_view_host()->process(); | 441 browser()->GetTabContentsAt(0)->render_view_host()->process(); |
440 EXPECT_TRUE(extension_process_manager->IsExtensionProcess( | 442 EXPECT_TRUE(extension_process_manager->IsExtensionProcess( |
441 process->id())); | 443 process->id())); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 content::Source<NavigationController>( | 494 content::Source<NavigationController>( |
493 &browser()->GetSelectedTabContentsWrapper()->controller())); | 495 &browser()->GetSelectedTabContentsWrapper()->controller())); |
494 browser()->Reload(CURRENT_TAB); | 496 browser()->Reload(CURRENT_TAB); |
495 observer.Wait(); | 497 observer.Wait(); |
496 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 498 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
497 contents->render_view_host(), L"", | 499 contents->render_view_host(), L"", |
498 L"window.domAutomationController.send(chrome.app.isInstalled)", | 500 L"window.domAutomationController.send(chrome.app.isInstalled)", |
499 &is_installed)); | 501 &is_installed)); |
500 ASSERT_TRUE(is_installed); | 502 ASSERT_TRUE(is_installed); |
501 } | 503 } |
OLD | NEW |