Chromium Code Reviews| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "chrome/browser/extensions/api/tabs/tabs_api.h" | 9 #include "chrome/browser/extensions/api/tabs/tabs_api.h" |
| 10 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 10 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
| 11 #include "chrome/browser/extensions/extension_apitest.h" | 11 #include "chrome/browser/extensions/extension_apitest.h" |
| 12 #include "chrome/browser/extensions/extension_function_test_utils.h" | 12 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 13 #include "chrome/browser/extensions/extension_tab_util.h" | 13 #include "chrome/browser/extensions/extension_tab_util.h" |
| 14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_window.h" | |
| 16 #include "chrome/test/base/in_process_browser_test.h" | 15 #include "chrome/test/base/in_process_browser_test.h" |
| 17 #include "chrome/test/base/interactive_test_utils.h" | 16 #include "chrome/test/base/interactive_test_utils.h" |
| 18 #include "chrome/test/base/ui_test_utils.h" | |
| 19 #include "extensions/browser/api_test_utils.h" | 17 #include "extensions/browser/api_test_utils.h" |
| 20 #include "extensions/common/test_util.h" | 18 #include "extensions/common/test_util.h" |
| 21 | 19 |
| 22 namespace api_test_utils = extensions::api_test_utils; | 20 namespace extensions { |
| 23 namespace keys = extensions::tabs_constants; | 21 |
| 22 namespace keys = tabs_constants; | |
| 24 namespace utils = extension_function_test_utils; | 23 namespace utils = extension_function_test_utils; |
| 25 | 24 |
| 26 typedef InProcessBrowserTest ExtensionTabsTest; | 25 using ExtensionTabsTest = InProcessBrowserTest; |
| 27 | 26 |
| 28 // http://crbug.com/154081 for Aura specific | 27 // http://crbug.com/154081 for Aura specific |
| 29 // http://crbug.com/179063 for other general failures on try bots. | 28 // http://crbug.com/179063 for other general failures on try bots. |
| 30 #if defined(OS_WIN) | 29 #if defined(OS_WIN) |
| 31 #define MAYBE_GetLastFocusedWindow DISABLED_GetLastFocusedWindow | 30 #define MAYBE_GetLastFocusedWindow DISABLED_GetLastFocusedWindow |
| 32 #else | 31 #else |
| 33 #define MAYBE_GetLastFocusedWindow GetLastFocusedWindow | 32 #define MAYBE_GetLastFocusedWindow GetLastFocusedWindow |
| 34 #endif | 33 #endif |
| 35 | 34 |
| 36 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, MAYBE_GetLastFocusedWindow) { | 35 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, MAYBE_GetLastFocusedWindow) { |
| 37 // Create a new window which making it the "last focused" window. | 36 // Create a new window which making it the "last focused" window. |
| 38 // Note that "last focused" means the "top" most window. | 37 // Note that "last focused" means the "top" most window. |
| 39 Browser* new_browser = CreateBrowser(browser()->profile()); | 38 Browser* new_browser = CreateBrowser(browser()->profile()); |
| 39 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(new_browser)); | |
| 40 | |
| 41 GURL url("about:blank"); | |
| 42 AddTabAtIndexToBrowser(new_browser, 0, url, ui::PAGE_TRANSITION_LINK, true); | |
| 43 | |
| 40 int focused_window_id = | 44 int focused_window_id = |
| 41 extensions::ExtensionTabUtil::GetWindowId(new_browser); | 45 extensions::ExtensionTabUtil::GetWindowId(new_browser); |
| 42 | 46 |
| 43 scoped_refptr<extensions::WindowsGetLastFocusedFunction> function = | 47 scoped_refptr<extensions::WindowsGetLastFocusedFunction> function = |
| 44 new extensions::WindowsGetLastFocusedFunction(); | 48 new extensions::WindowsGetLastFocusedFunction(); |
| 45 scoped_refptr<extensions::Extension> extension( | 49 scoped_refptr<extensions::Extension> extension( |
| 46 extensions::test_util::CreateEmptyExtension()); | 50 extensions::test_util::CreateEmptyExtension()); |
| 47 function->set_extension(extension.get()); | 51 function->set_extension(extension.get()); |
| 48 std::unique_ptr<base::DictionaryValue> result( | 52 std::unique_ptr<base::DictionaryValue> result( |
| 49 utils::ToDictionary(utils::RunFunctionAndReturnSingleResult( | 53 utils::ToDictionary(utils::RunFunctionAndReturnSingleResult( |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 68 // "populate" was enabled so tabs should be populated. | 72 // "populate" was enabled so tabs should be populated. |
| 69 EXPECT_TRUE(result.get()->GetList(keys::kTabsKey, &tabs)); | 73 EXPECT_TRUE(result.get()->GetList(keys::kTabsKey, &tabs)); |
| 70 } | 74 } |
| 71 | 75 |
| 72 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, QueryLastFocusedWindowTabs) { | 76 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, QueryLastFocusedWindowTabs) { |
| 73 const size_t kExtraWindows = 2; | 77 const size_t kExtraWindows = 2; |
| 74 for (size_t i = 0; i < kExtraWindows; ++i) | 78 for (size_t i = 0; i < kExtraWindows; ++i) |
| 75 CreateBrowser(browser()->profile()); | 79 CreateBrowser(browser()->profile()); |
| 76 | 80 |
| 77 Browser* focused_window = CreateBrowser(browser()->profile()); | 81 Browser* focused_window = CreateBrowser(browser()->profile()); |
| 78 #if defined(OS_MACOSX) | 82 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(focused_window)); |
| 79 // See BrowserWindowCocoa::Show. In tests, Browser::window()->IsActive won't | |
| 80 // work unless we fake the browser being launched by the user. | |
| 81 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( | |
| 82 focused_window->window()->GetNativeWindow())); | |
| 83 #endif | |
| 84 ui_test_utils::BrowserActivationWaiter waiter(focused_window); | |
| 85 waiter.WaitForActivation(); | |
| 86 | 83 |
| 87 GURL url("about:blank"); | 84 GURL url("about:blank"); |
| 88 AddTabAtIndexToBrowser(focused_window, 0, url, ui::PAGE_TRANSITION_LINK, | 85 AddTabAtIndexToBrowser(focused_window, 0, url, ui::PAGE_TRANSITION_LINK, |
| 89 true); | 86 true); |
| 90 int focused_window_id = | 87 int focused_window_id = |
| 91 extensions::ExtensionTabUtil::GetWindowId(focused_window); | 88 extensions::ExtensionTabUtil::GetWindowId(focused_window); |
| 92 | 89 |
| 93 // Get tabs in the 'last focused' window called from non-focused browser. | 90 // Get tabs in the 'last focused' window called from non-focused browser. |
| 94 scoped_refptr<extensions::TabsQueryFunction> function = | 91 scoped_refptr<extensions::TabsQueryFunction> function = |
| 95 new extensions::TabsQueryFunction(); | 92 new extensions::TabsQueryFunction(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 api_test_utils::GetInteger(result_tab, keys::kWindowIdKey)); | 125 api_test_utils::GetInteger(result_tab, keys::kWindowIdKey)); |
| 129 } | 126 } |
| 130 } | 127 } |
| 131 | 128 |
| 132 #if defined(OS_WIN) // http://crbug.com/154081 && http://crbug.com/171080 | 129 #if defined(OS_WIN) // http://crbug.com/154081 && http://crbug.com/171080 |
| 133 #define MAYBE_TabCurrentWindow DISABLED_TabCurrentWindow | 130 #define MAYBE_TabCurrentWindow DISABLED_TabCurrentWindow |
| 134 #else | 131 #else |
| 135 #define MAYBE_TabCurrentWindow TabCurrentWindow | 132 #define MAYBE_TabCurrentWindow TabCurrentWindow |
| 136 #endif | 133 #endif |
| 137 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_TabCurrentWindow) { | 134 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_TabCurrentWindow) { |
| 135 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | |
|
sky
2016/11/15 20:21:11
Is this really necessary? interactive_ui_tests_mai
Qiang(Joe) Xu
2016/11/15 22:42:29
Yes, I saw it was done for all platforms except ma
| |
| 138 ASSERT_TRUE(RunExtensionTest("tabs/current_window")) << message_; | 136 ASSERT_TRUE(RunExtensionTest("tabs/current_window")) << message_; |
| 139 } | 137 } |
| 138 | |
| 139 } // namespace extensions | |
| OLD | NEW |