| OLD | NEW |
| 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/memory/scoped_vector.h" | 6 #include "base/memory/scoped_vector.h" |
| 7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "chrome/browser/extensions/extension_apitest.h" | 8 #include "chrome/browser/extensions/extension_apitest.h" |
| 9 #include "chrome/browser/extensions/extension_host.h" | 9 #include "chrome/browser/extensions/extension_host.h" |
| 10 #include "chrome/browser/extensions/extension_process_manager.h" | 10 #include "chrome/browser/extensions/extension_process_manager.h" |
| 11 #include "chrome/browser/extensions/extension_system.h" | 11 #include "chrome/browser/extensions/extension_system.h" |
| 12 #include "chrome/browser/extensions/extension_test_message_listener.h" | 12 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/browser_finder.h" | 14 #include "chrome/browser/ui/browser_finder.h" |
| 15 #include "chrome/browser/ui/browser_list.h" | 15 #include "chrome/browser/ui/browser_iterator.h" |
| 16 #include "chrome/browser/ui/browser_tabstrip.h" | 16 #include "chrome/browser/ui/browser_tabstrip.h" |
| 17 #include "chrome/browser/ui/panels/panel_manager.h" | 17 #include "chrome/browser/ui/panels/panel_manager.h" |
| 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 19 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| 20 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
| 21 #include "chrome/test/base/ui_test_utils.h" | 21 #include "chrome/test/base/ui_test_utils.h" |
| 22 #include "content/public/browser/render_process_host.h" | 22 #include "content/public/browser/render_process_host.h" |
| 23 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 24 #include "content/public/common/result_codes.h" | 24 #include "content/public/common/result_codes.h" |
| 25 #include "content/public/test/browser_test_utils.h" | 25 #include "content/public/test/browser_test_utils.h" |
| 26 #include "net/base/mock_host_resolver.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 27 #include "net/base/mock_host_resolver.h" | |
| 28 | 28 |
| 29 using content::OpenURLParams; | 29 using content::OpenURLParams; |
| 30 using content::Referrer; | 30 using content::Referrer; |
| 31 using content::WebContents; | 31 using content::WebContents; |
| 32 | 32 |
| 33 // Disabled, http://crbug.com/64899. | 33 // Disabled, http://crbug.com/64899. |
| 34 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpen) { | 34 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpen) { |
| 35 CommandLine::ForCurrentProcess()->AppendSwitch( | 35 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 36 switches::kEnableExperimentalExtensionApis); | 36 switches::kEnableExperimentalExtensionApis); |
| 37 | 37 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 61 break; | 61 break; |
| 62 | 62 |
| 63 content::RunAllPendingInMessageLoop(); | 63 content::RunAllPendingInMessageLoop(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 EXPECT_EQ(num_browsers, chrome::GetBrowserCount(browser->profile())); | 66 EXPECT_EQ(num_browsers, chrome::GetBrowserCount(browser->profile())); |
| 67 EXPECT_EQ(num_tabs, browser->tab_strip_model()->count()); | 67 EXPECT_EQ(num_tabs, browser->tab_strip_model()->count()); |
| 68 EXPECT_EQ(num_panels, PanelManager::GetInstance()->num_panels()); | 68 EXPECT_EQ(num_panels, PanelManager::GetInstance()->num_panels()); |
| 69 | 69 |
| 70 int num_popups_seen = 0; | 70 int num_popups_seen = 0; |
| 71 for (BrowserList::const_iterator iter = BrowserList::begin(); | 71 for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) { |
| 72 iter != BrowserList::end(); ++iter) { | |
| 73 if (*iter == browser) | 72 if (*iter == browser) |
| 74 continue; | 73 continue; |
| 75 | 74 |
| 76 // Check for TYPE_POPUP. | 75 // Check for TYPE_POPUP. |
| 77 // TODO: this ifdef will have to be updated when we have win ash bots running | 76 // TODO: this ifdef will have to be updated when we have win ash bots running |
| 78 // browser_tests. | 77 // browser_tests. |
| 79 #if defined(USE_ASH) && !defined(OS_WIN) | 78 #if defined(USE_ASH) && !defined(OS_WIN) |
| 80 // On Ash, panel windows open as popup windows. | 79 // On Ash, panel windows open as popup windows. |
| 81 EXPECT_TRUE((*iter)->is_type_popup() || (*iter)->is_type_panel()); | 80 EXPECT_TRUE((*iter)->is_type_popup() || (*iter)->is_type_panel()); |
| 82 #else | 81 #else |
| 83 EXPECT_TRUE((*iter)->is_type_popup()); | 82 EXPECT_TRUE((*iter)->is_type_popup()); |
| 84 #endif | 83 #endif |
| 85 ++num_popups_seen; | 84 ++num_popups_seen; |
| 86 | |
| 87 } | 85 } |
| 88 EXPECT_EQ(num_popups, num_popups_seen); | 86 EXPECT_EQ(num_popups, num_popups_seen); |
| 89 } | 87 } |
| 90 | 88 |
| 91 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BrowserIsApp) { | 89 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BrowserIsApp) { |
| 92 host_resolver()->AddRule("a.com", "127.0.0.1"); | 90 host_resolver()->AddRule("a.com", "127.0.0.1"); |
| 93 ASSERT_TRUE(StartTestServer()); | 91 ASSERT_TRUE(StartTestServer()); |
| 94 ASSERT_TRUE(LoadExtension( | 92 ASSERT_TRUE(LoadExtension( |
| 95 test_data_dir_.AppendASCII("window_open").AppendASCII("browser_is_app"))); | 93 test_data_dir_.AppendASCII("window_open").AppendASCII("browser_is_app"))); |
| 96 | 94 |
| 97 WaitForTabsAndPopups(browser(), 0, 2, 0); | 95 WaitForTabsAndPopups(browser(), 0, 2, 0); |
| 98 | 96 |
| 99 for (BrowserList::const_iterator iter = BrowserList::begin(); | 97 for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) { |
| 100 iter != BrowserList::end(); ++iter) { | |
| 101 if (*iter == browser()) | 98 if (*iter == browser()) |
| 102 ASSERT_FALSE((*iter)->is_app()); | 99 ASSERT_FALSE(iter->is_app()); |
| 103 else | 100 else |
| 104 ASSERT_TRUE((*iter)->is_app()); | 101 ASSERT_TRUE(iter->is_app()); |
| 105 } | 102 } |
| 106 } | 103 } |
| 107 | 104 |
| 108 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupDefault) { | 105 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupDefault) { |
| 109 ASSERT_TRUE(StartTestServer()); | 106 ASSERT_TRUE(StartTestServer()); |
| 110 ASSERT_TRUE(LoadExtension( | 107 ASSERT_TRUE(LoadExtension( |
| 111 test_data_dir_.AppendASCII("window_open").AppendASCII("popup"))); | 108 test_data_dir_.AppendASCII("window_open").AppendASCII("popup"))); |
| 112 | 109 |
| 113 const int num_tabs = 1; | 110 const int num_tabs = 1; |
| 114 const int num_popups = 0; | 111 const int num_popups = 0; |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(), | 426 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(), |
| 430 GURL(std::string("chrome-extension://") + last_loaded_extension_id_ + | 427 GURL(std::string("chrome-extension://") + last_loaded_extension_id_ + |
| 431 "/newtab.html"), false, &newtab)); | 428 "/newtab.html"), false, &newtab)); |
| 432 | 429 |
| 433 // Extension API should succeed. | 430 // Extension API should succeed. |
| 434 bool result = false; | 431 bool result = false; |
| 435 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()", | 432 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()", |
| 436 &result)); | 433 &result)); |
| 437 EXPECT_TRUE(result); | 434 EXPECT_TRUE(result); |
| 438 } | 435 } |
| OLD | NEW |