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