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" |
| 6 |
5 #include "base/values.h" | 7 #include "base/values.h" |
6 #include "chrome/browser/extensions/api/tabs/tabs_api.h" | |
7 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 8 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
8 #include "chrome/browser/extensions/extension_apitest.h" | 9 #include "chrome/browser/extensions/extension_apitest.h" |
9 #include "chrome/browser/extensions/extension_function_test_utils.h" | 10 #include "chrome/browser/extensions/extension_function_test_utils.h" |
10 #include "chrome/browser/extensions/extension_tab_util.h" | 11 #include "chrome/browser/extensions/extension_tab_util.h" |
11 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/browser_window.h" | 13 #include "chrome/browser/ui/browser_window.h" |
| 14 #include "chrome/test/base/interactive_test_utils.h" |
13 #include "chrome/test/base/in_process_browser_test.h" | 15 #include "chrome/test/base/in_process_browser_test.h" |
14 #include "chrome/test/base/interactive_test_utils.h" | |
15 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
16 | 17 |
17 namespace keys = extensions::tabs_constants; | 18 namespace keys = extensions::tabs_constants; |
18 namespace utils = extension_function_test_utils; | 19 namespace utils = extension_function_test_utils; |
19 | 20 |
20 typedef InProcessBrowserTest ExtensionTabsTest; | 21 typedef InProcessBrowserTest ExtensionTabsTest; |
21 | 22 |
22 #if defined(OS_WIN) && defined(USE_AURA) // http://crbug.com/154081 | 23 #if defined(OS_WIN) && defined(USE_AURA) // http://crbug.com/154081 |
23 #define MAYBE_GetLastFocusedWindow DISABLED_GetLastFocusedWindow | 24 #define MAYBE_GetLastFocusedWindow DISABLED_GetLastFocusedWindow |
24 #else | 25 #else |
25 #define MAYBE_GetLastFocusedWindow GetLastFocusedWindow | 26 #define MAYBE_GetLastFocusedWindow GetLastFocusedWindow |
26 #endif | 27 #endif |
27 | 28 |
28 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, MAYBE_GetLastFocusedWindow) { | 29 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, MAYBE_GetLastFocusedWindow) { |
29 // Create a new window which making it the "last focused" window. | 30 // Create a new window which making it the "last focused" window. |
30 // Note that "last focused" means the "top" most window. | 31 // Note that "last focused" means the "top" most window. |
31 Browser* new_browser = CreateBrowser(browser()->profile()); | 32 Browser* new_browser = CreateBrowser(browser()->profile()); |
32 int focused_window_id = ExtensionTabUtil::GetWindowId(new_browser); | 33 int focused_window_id = ExtensionTabUtil::GetWindowId(new_browser); |
33 | 34 |
34 scoped_refptr<WindowsGetLastFocusedFunction> function = | 35 scoped_refptr<GetLastFocusedWindowFunction> function = |
35 new WindowsGetLastFocusedFunction(); | 36 new GetLastFocusedWindowFunction(); |
36 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension()); | 37 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension()); |
37 function->set_extension(extension.get()); | 38 function->set_extension(extension.get()); |
38 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( | 39 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( |
39 utils::RunFunctionAndReturnSingleResult(function.get(), | 40 utils::RunFunctionAndReturnSingleResult(function.get(), |
40 "[]", | 41 "[]", |
41 new_browser))); | 42 new_browser))); |
42 | 43 |
43 // The id should always match the last focused window and does not depend | 44 // The id should always match the last focused window and does not depend |
44 // on what was passed to RunFunctionAndReturnSingleResult. | 45 // on what was passed to RunFunctionAndReturnSingleResult. |
45 EXPECT_EQ(focused_window_id, utils::GetInteger(result.get(), "id")); | 46 EXPECT_EQ(focused_window_id, utils::GetInteger(result.get(), "id")); |
46 ListValue* tabs = NULL; | 47 ListValue* tabs = NULL; |
47 EXPECT_FALSE(result.get()->GetList(keys::kTabsKey, &tabs)); | 48 EXPECT_FALSE(result.get()->GetList(keys::kTabsKey, &tabs)); |
48 | 49 |
49 function = new WindowsGetLastFocusedFunction(); | 50 function = new GetLastFocusedWindowFunction(); |
50 function->set_extension(extension.get()); | 51 function->set_extension(extension.get()); |
51 result.reset(utils::ToDictionary( | 52 result.reset(utils::ToDictionary( |
52 utils::RunFunctionAndReturnSingleResult(function.get(), | 53 utils::RunFunctionAndReturnSingleResult(function.get(), |
53 "[{\"populate\": true}]", | 54 "[{\"populate\": true}]", |
54 browser()))); | 55 browser()))); |
55 | 56 |
56 // The id should always match the last focused window and does not depend | 57 // The id should always match the last focused window and does not depend |
57 // on what was passed to RunFunctionAndReturnSingleResult. | 58 // on what was passed to RunFunctionAndReturnSingleResult. |
58 EXPECT_EQ(focused_window_id, utils::GetInteger(result.get(), "id")); | 59 EXPECT_EQ(focused_window_id, utils::GetInteger(result.get(), "id")); |
59 // "populate" was enabled so tabs should be populated. | 60 // "populate" was enabled so tabs should be populated. |
(...skipping 15 matching lines...) Expand all Loading... |
75 #endif | 76 #endif |
76 | 77 |
77 // Needed on Mac and Linux so that the BrowserWindow::IsActive calls work. | 78 // Needed on Mac and Linux so that the BrowserWindow::IsActive calls work. |
78 content::RunAllPendingInMessageLoop(); | 79 content::RunAllPendingInMessageLoop(); |
79 | 80 |
80 GURL url; | 81 GURL url; |
81 AddTabAtIndexToBrowser(focused_window, 0, url, content::PAGE_TRANSITION_LINK); | 82 AddTabAtIndexToBrowser(focused_window, 0, url, content::PAGE_TRANSITION_LINK); |
82 int focused_window_id = ExtensionTabUtil::GetWindowId(focused_window); | 83 int focused_window_id = ExtensionTabUtil::GetWindowId(focused_window); |
83 | 84 |
84 // Get tabs in the 'last focused' window called from non-focused browser. | 85 // Get tabs in the 'last focused' window called from non-focused browser. |
85 scoped_refptr<TabsQueryFunction> function = new TabsQueryFunction(); | 86 scoped_refptr<QueryTabsFunction> function = new QueryTabsFunction(); |
86 scoped_ptr<base::ListValue> result(utils::ToList( | 87 scoped_ptr<base::ListValue> result(utils::ToList( |
87 utils::RunFunctionAndReturnSingleResult(function.get(), | 88 utils::RunFunctionAndReturnSingleResult(function.get(), |
88 "[{\"lastFocusedWindow\":true}]", | 89 "[{\"lastFocusedWindow\":true}]", |
89 browser()))); | 90 browser()))); |
90 | 91 |
91 ListValue* result_tabs = result.get(); | 92 ListValue* result_tabs = result.get(); |
92 // We should have one initial tab and one added tab. | 93 // We should have one initial tab and one added tab. |
93 EXPECT_EQ(2u, result_tabs->GetSize()); | 94 EXPECT_EQ(2u, result_tabs->GetSize()); |
94 for (size_t i = 0; i < result_tabs->GetSize(); ++i) { | 95 for (size_t i = 0; i < result_tabs->GetSize(); ++i) { |
95 DictionaryValue* result_tab = NULL; | 96 DictionaryValue* result_tab = NULL; |
96 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); | 97 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); |
97 EXPECT_EQ(focused_window_id, utils::GetInteger(result_tab, | 98 EXPECT_EQ(focused_window_id, utils::GetInteger(result_tab, |
98 keys::kWindowIdKey)); | 99 keys::kWindowIdKey)); |
99 } | 100 } |
100 | 101 |
101 // Get tabs NOT in the 'last focused' window called from the focused browser. | 102 // Get tabs NOT in the 'last focused' window called from the focused browser. |
102 function = new TabsQueryFunction(); | 103 function = new QueryTabsFunction(); |
103 result.reset(utils::ToList( | 104 result.reset(utils::ToList( |
104 utils::RunFunctionAndReturnSingleResult(function.get(), | 105 utils::RunFunctionAndReturnSingleResult(function.get(), |
105 "[{\"lastFocusedWindow\":false}]", | 106 "[{\"lastFocusedWindow\":false}]", |
106 browser()))); | 107 browser()))); |
107 | 108 |
108 result_tabs = result.get(); | 109 result_tabs = result.get(); |
109 // We should get one tab for each extra window and one for the initial window. | 110 // We should get one tab for each extra window and one for the initial window. |
110 EXPECT_EQ(kExtraWindows + 1, result_tabs->GetSize()); | 111 EXPECT_EQ(kExtraWindows + 1, result_tabs->GetSize()); |
111 for (size_t i = 0; i < result_tabs->GetSize(); ++i) { | 112 for (size_t i = 0; i < result_tabs->GetSize(); ++i) { |
112 DictionaryValue* result_tab = NULL; | 113 DictionaryValue* result_tab = NULL; |
113 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); | 114 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); |
114 EXPECT_NE(focused_window_id, utils::GetInteger(result_tab, | 115 EXPECT_NE(focused_window_id, utils::GetInteger(result_tab, |
115 keys::kWindowIdKey)); | 116 keys::kWindowIdKey)); |
116 } | 117 } |
117 } | 118 } |
118 | 119 |
119 #if defined(OS_WIN) && defined(USE_AURA) // http://crbug.com/154081 | 120 #if defined(OS_WIN) && defined(USE_AURA) // http://crbug.com/154081 |
120 #define MAYBE_TabCurrentWindow DISABLED_TabCurrentWindow | 121 #define MAYBE_TabCurrentWindow DISABLED_TabCurrentWindow |
121 #else | 122 #else |
122 #define MAYBE_TabCurrentWindow TabCurrentWindow | 123 #define MAYBE_TabCurrentWindow TabCurrentWindow |
123 #endif | 124 #endif |
124 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_TabCurrentWindow) { | 125 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_TabCurrentWindow) { |
125 ASSERT_TRUE(RunExtensionTest("tabs/current_window")) << message_; | 126 ASSERT_TRUE(RunExtensionTest("tabs/current_window")) << message_; |
126 } | 127 } |
OLD | NEW |