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" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 "[{\"populate\": true}]", | 62 "[{\"populate\": true}]", |
63 browser()))); | 63 browser()))); |
64 | 64 |
65 // The id should always match the last focused window and does not depend | 65 // The id should always match the last focused window and does not depend |
66 // on what was passed to RunFunctionAndReturnSingleResult. | 66 // on what was passed to RunFunctionAndReturnSingleResult. |
67 EXPECT_EQ(focused_window_id, api_test_utils::GetInteger(result.get(), "id")); | 67 EXPECT_EQ(focused_window_id, api_test_utils::GetInteger(result.get(), "id")); |
68 // "populate" was enabled so tabs should be populated. | 68 // "populate" was enabled so tabs should be populated. |
69 EXPECT_TRUE(result.get()->GetList(keys::kTabsKey, &tabs)); | 69 EXPECT_TRUE(result.get()->GetList(keys::kTabsKey, &tabs)); |
70 } | 70 } |
71 | 71 |
72 // Flaky: http://crbug.com/136562 | 72 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, QueryLastFocusedWindowTabs) { |
73 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DISABLED_QueryLastFocusedWindowTabs) { | |
74 const size_t kExtraWindows = 2; | 73 const size_t kExtraWindows = 2; |
75 for (size_t i = 0; i < kExtraWindows; ++i) | 74 for (size_t i = 0; i < kExtraWindows; ++i) |
76 CreateBrowser(browser()->profile()); | 75 CreateBrowser(browser()->profile()); |
77 | 76 |
78 Browser* focused_window = CreateBrowser(browser()->profile()); | 77 Browser* focused_window = CreateBrowser(browser()->profile()); |
79 #if defined(OS_MACOSX) | 78 #if defined(OS_MACOSX) |
80 // See BrowserWindowCocoa::Show. In tests, Browser::window()->IsActive won't | 79 // See BrowserWindowCocoa::Show. In tests, Browser::window()->IsActive won't |
81 // work unless we fake the browser being launched by the user. | 80 // work unless we fake the browser being launched by the user. |
82 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( | 81 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( |
83 focused_window->window()->GetNativeWindow())); | 82 focused_window->window()->GetNativeWindow())); |
84 #endif | 83 #endif |
| 84 ui_test_utils::BrowserActivationWaiter waiter(focused_window); |
| 85 waiter.WaitForActivation(); |
85 | 86 |
86 // Needed on Mac and Linux so that the BrowserWindow::IsActive calls work. | 87 GURL url("about:blank"); |
87 content::RunAllPendingInMessageLoop(); | |
88 | |
89 GURL url; | |
90 AddTabAtIndexToBrowser(focused_window, 0, url, ui::PAGE_TRANSITION_LINK, | 88 AddTabAtIndexToBrowser(focused_window, 0, url, ui::PAGE_TRANSITION_LINK, |
91 true); | 89 true); |
92 int focused_window_id = | 90 int focused_window_id = |
93 extensions::ExtensionTabUtil::GetWindowId(focused_window); | 91 extensions::ExtensionTabUtil::GetWindowId(focused_window); |
94 | 92 |
95 // Get tabs in the 'last focused' window called from non-focused browser. | 93 // Get tabs in the 'last focused' window called from non-focused browser. |
96 scoped_refptr<extensions::TabsQueryFunction> function = | 94 scoped_refptr<extensions::TabsQueryFunction> function = |
97 new extensions::TabsQueryFunction(); | 95 new extensions::TabsQueryFunction(); |
| 96 scoped_refptr<extensions::Extension> extension( |
| 97 extensions::test_util::CreateEmptyExtension()); |
| 98 function->set_extension(extension.get()); |
98 std::unique_ptr<base::ListValue> result( | 99 std::unique_ptr<base::ListValue> result( |
99 utils::ToList(utils::RunFunctionAndReturnSingleResult( | 100 utils::ToList(utils::RunFunctionAndReturnSingleResult( |
100 function.get(), "[{\"lastFocusedWindow\":true}]", browser()))); | 101 function.get(), "[{\"lastFocusedWindow\":true}]", browser()))); |
101 | 102 |
102 base::ListValue* result_tabs = result.get(); | 103 base::ListValue* result_tabs = result.get(); |
103 // We should have one initial tab and one added tab. | 104 // We should have one initial tab and one added tab. |
104 EXPECT_EQ(2u, result_tabs->GetSize()); | 105 EXPECT_EQ(2u, result_tabs->GetSize()); |
105 for (size_t i = 0; i < result_tabs->GetSize(); ++i) { | 106 for (size_t i = 0; i < result_tabs->GetSize(); ++i) { |
106 base::DictionaryValue* result_tab = NULL; | 107 base::DictionaryValue* result_tab = NULL; |
107 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); | 108 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); |
108 EXPECT_EQ(focused_window_id, | 109 EXPECT_EQ(focused_window_id, |
109 api_test_utils::GetInteger(result_tab, keys::kWindowIdKey)); | 110 api_test_utils::GetInteger(result_tab, keys::kWindowIdKey)); |
110 } | 111 } |
111 | 112 |
112 // Get tabs NOT in the 'last focused' window called from the focused browser. | 113 // Get tabs NOT in the 'last focused' window called from the focused browser. |
113 function = new extensions::TabsQueryFunction(); | 114 function = new extensions::TabsQueryFunction(); |
| 115 function->set_extension(extension.get()); |
114 result.reset(utils::ToList( | 116 result.reset(utils::ToList( |
115 utils::RunFunctionAndReturnSingleResult(function.get(), | 117 utils::RunFunctionAndReturnSingleResult(function.get(), |
116 "[{\"lastFocusedWindow\":false}]", | 118 "[{\"lastFocusedWindow\":false}]", |
117 browser()))); | 119 browser()))); |
118 | 120 |
119 result_tabs = result.get(); | 121 result_tabs = result.get(); |
120 // We should get one tab for each extra window and one for the initial window. | 122 // We should get one tab for each extra window and one for the initial window. |
121 EXPECT_EQ(kExtraWindows + 1, result_tabs->GetSize()); | 123 EXPECT_EQ(kExtraWindows + 1, result_tabs->GetSize()); |
122 for (size_t i = 0; i < result_tabs->GetSize(); ++i) { | 124 for (size_t i = 0; i < result_tabs->GetSize(); ++i) { |
123 base::DictionaryValue* result_tab = NULL; | 125 base::DictionaryValue* result_tab = NULL; |
124 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); | 126 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); |
125 EXPECT_NE(focused_window_id, | 127 EXPECT_NE(focused_window_id, |
126 api_test_utils::GetInteger(result_tab, keys::kWindowIdKey)); | 128 api_test_utils::GetInteger(result_tab, keys::kWindowIdKey)); |
127 } | 129 } |
128 } | 130 } |
129 | 131 |
130 #if defined(OS_WIN) // http://crbug.com/154081 && http://crbug.com/171080 | 132 #if defined(OS_WIN) // http://crbug.com/154081 && http://crbug.com/171080 |
131 #define MAYBE_TabCurrentWindow DISABLED_TabCurrentWindow | 133 #define MAYBE_TabCurrentWindow DISABLED_TabCurrentWindow |
132 #else | 134 #else |
133 #define MAYBE_TabCurrentWindow TabCurrentWindow | 135 #define MAYBE_TabCurrentWindow TabCurrentWindow |
134 #endif | 136 #endif |
135 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_TabCurrentWindow) { | 137 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_TabCurrentWindow) { |
136 ASSERT_TRUE(RunExtensionTest("tabs/current_window")) << message_; | 138 ASSERT_TRUE(RunExtensionTest("tabs/current_window")) << message_; |
137 } | 139 } |
OLD | NEW |