| 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 "chrome/browser/extensions/api/tabs/tabs.h" | 5 #include "chrome/browser/extensions/api/tabs/tabs.h" |
| 6 | 6 |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 8 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
| 9 #include "chrome/browser/extensions/extension_function_test_utils.h" | 9 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 10 #include "chrome/browser/extensions/extension_tab_util.h" | 10 #include "chrome/browser/extensions/extension_tab_util.h" |
| 11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/browser_window.h" |
| 13 #include "chrome/test/base/interactive_test_utils.h" |
| 12 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
| 13 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
| 14 | 16 |
| 15 namespace keys = extensions::tabs_constants; | 17 namespace keys = extensions::tabs_constants; |
| 16 namespace utils = extension_function_test_utils; | 18 namespace utils = extension_function_test_utils; |
| 17 | 19 |
| 18 typedef InProcessBrowserTest ExtensionTabsTest; | 20 typedef InProcessBrowserTest ExtensionTabsTest; |
| 19 | 21 |
| 20 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetLastFocusedWindow) { | 22 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetLastFocusedWindow) { |
| 21 // Create a new window which making it the "last focused" window. | 23 // Create a new window which making it the "last focused" window. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 44 utils::RunFunctionAndReturnSingleResult(function.get(), | 46 utils::RunFunctionAndReturnSingleResult(function.get(), |
| 45 "[{\"populate\": true}]", | 47 "[{\"populate\": true}]", |
| 46 browser()))); | 48 browser()))); |
| 47 | 49 |
| 48 // The id should always match the last focused window and does not depend | 50 // The id should always match the last focused window and does not depend |
| 49 // on what was passed to RunFunctionAndReturnSingleResult. | 51 // on what was passed to RunFunctionAndReturnSingleResult. |
| 50 EXPECT_EQ(focused_window_id, utils::GetInteger(result.get(), "id")); | 52 EXPECT_EQ(focused_window_id, utils::GetInteger(result.get(), "id")); |
| 51 // "populate" was enabled so tabs should be populated. | 53 // "populate" was enabled so tabs should be populated. |
| 52 EXPECT_TRUE(result.get()->GetList(keys::kTabsKey, &tabs)); | 54 EXPECT_TRUE(result.get()->GetList(keys::kTabsKey, &tabs)); |
| 53 } | 55 } |
| 56 |
| 57 // Flaky: http://crbug.com/136562 |
| 58 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DISABLED_QueryLastFocusedWindowTabs) { |
| 59 const size_t kExtraWindows = 2; |
| 60 for (size_t i = 0; i < kExtraWindows; ++i) |
| 61 CreateBrowser(browser()->profile()); |
| 62 |
| 63 Browser* focused_window = CreateBrowser(browser()->profile()); |
| 64 #if defined(OS_MACOSX) |
| 65 // See BrowserWindowCocoa::Show. In tests, Browser::window()->IsActive won't |
| 66 // work unless we fake the browser being launched by the user. |
| 67 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( |
| 68 focused_window->window()->GetNativeWindow())); |
| 69 #endif |
| 70 |
| 71 // Needed on Mac and Linux so that the BrowserWindow::IsActive calls work. |
| 72 content::RunAllPendingInMessageLoop(); |
| 73 |
| 74 GURL url; |
| 75 AddTabAtIndexToBrowser(focused_window, 0, url, content::PAGE_TRANSITION_LINK); |
| 76 int focused_window_id = ExtensionTabUtil::GetWindowId(focused_window); |
| 77 |
| 78 // Get tabs in the 'last focused' window called from non-focused browser. |
| 79 scoped_refptr<QueryTabsFunction> function = new QueryTabsFunction(); |
| 80 scoped_ptr<base::ListValue> result(utils::ToList( |
| 81 utils::RunFunctionAndReturnSingleResult(function.get(), |
| 82 "[{\"lastFocusedWindow\":true}]", |
| 83 browser()))); |
| 84 |
| 85 ListValue* result_tabs = result.get(); |
| 86 // We should have one initial tab and one added tab. |
| 87 EXPECT_EQ(2u, result_tabs->GetSize()); |
| 88 for (size_t i = 0; i < result_tabs->GetSize(); ++i) { |
| 89 DictionaryValue* result_tab = NULL; |
| 90 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); |
| 91 EXPECT_EQ(focused_window_id, utils::GetInteger(result_tab, |
| 92 keys::kWindowIdKey)); |
| 93 } |
| 94 |
| 95 // Get tabs NOT in the 'last focused' window called from the focused browser. |
| 96 function = new QueryTabsFunction(); |
| 97 result.reset(utils::ToList( |
| 98 utils::RunFunctionAndReturnSingleResult(function.get(), |
| 99 "[{\"lastFocusedWindow\":false}]", |
| 100 browser()))); |
| 101 |
| 102 result_tabs = result.get(); |
| 103 // We should get one tab for each extra window and one for the initial window. |
| 104 EXPECT_EQ(kExtraWindows + 1, result_tabs->GetSize()); |
| 105 for (size_t i = 0; i < result_tabs->GetSize(); ++i) { |
| 106 DictionaryValue* result_tab = NULL; |
| 107 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); |
| 108 EXPECT_NE(focused_window_id, utils::GetInteger(result_tab, |
| 109 keys::kWindowIdKey)); |
| 110 } |
| 111 } |
| OLD | NEW |