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 "base/values.h" | 5 #include "base/values.h" |
6 #include "chrome/browser/extensions/api/tabs/tabs_api.h" | 6 #include "chrome/browser/extensions/api/tabs/tabs_api.h" |
7 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 7 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
8 #include "chrome/browser/extensions/extension_apitest.h" | 8 #include "chrome/browser/extensions/extension_apitest.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" |
(...skipping 27 matching lines...) Expand all Loading... |
38 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension()); | 38 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension()); |
39 function->set_extension(extension.get()); | 39 function->set_extension(extension.get()); |
40 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( | 40 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( |
41 utils::RunFunctionAndReturnSingleResult(function.get(), | 41 utils::RunFunctionAndReturnSingleResult(function.get(), |
42 "[]", | 42 "[]", |
43 new_browser))); | 43 new_browser))); |
44 | 44 |
45 // The id should always match the last focused window and does not depend | 45 // The id should always match the last focused window and does not depend |
46 // on what was passed to RunFunctionAndReturnSingleResult. | 46 // on what was passed to RunFunctionAndReturnSingleResult. |
47 EXPECT_EQ(focused_window_id, utils::GetInteger(result.get(), "id")); | 47 EXPECT_EQ(focused_window_id, utils::GetInteger(result.get(), "id")); |
48 ListValue* tabs = NULL; | 48 base::ListValue* tabs = NULL; |
49 EXPECT_FALSE(result.get()->GetList(keys::kTabsKey, &tabs)); | 49 EXPECT_FALSE(result.get()->GetList(keys::kTabsKey, &tabs)); |
50 | 50 |
51 function = new extensions::WindowsGetLastFocusedFunction(); | 51 function = new extensions::WindowsGetLastFocusedFunction(); |
52 function->set_extension(extension.get()); | 52 function->set_extension(extension.get()); |
53 result.reset(utils::ToDictionary( | 53 result.reset(utils::ToDictionary( |
54 utils::RunFunctionAndReturnSingleResult(function.get(), | 54 utils::RunFunctionAndReturnSingleResult(function.get(), |
55 "[{\"populate\": true}]", | 55 "[{\"populate\": true}]", |
56 browser()))); | 56 browser()))); |
57 | 57 |
58 // The id should always match the last focused window and does not depend | 58 // The id should always match the last focused window and does not depend |
(...skipping 25 matching lines...) Expand all Loading... |
84 int focused_window_id = ExtensionTabUtil::GetWindowId(focused_window); | 84 int focused_window_id = ExtensionTabUtil::GetWindowId(focused_window); |
85 | 85 |
86 // Get tabs in the 'last focused' window called from non-focused browser. | 86 // Get tabs in the 'last focused' window called from non-focused browser. |
87 scoped_refptr<extensions::TabsQueryFunction> function = | 87 scoped_refptr<extensions::TabsQueryFunction> function = |
88 new extensions::TabsQueryFunction(); | 88 new extensions::TabsQueryFunction(); |
89 scoped_ptr<base::ListValue> result(utils::ToList( | 89 scoped_ptr<base::ListValue> result(utils::ToList( |
90 utils::RunFunctionAndReturnSingleResult(function.get(), | 90 utils::RunFunctionAndReturnSingleResult(function.get(), |
91 "[{\"lastFocusedWindow\":true}]", | 91 "[{\"lastFocusedWindow\":true}]", |
92 browser()))); | 92 browser()))); |
93 | 93 |
94 ListValue* result_tabs = result.get(); | 94 base::ListValue* result_tabs = result.get(); |
95 // We should have one initial tab and one added tab. | 95 // We should have one initial tab and one added tab. |
96 EXPECT_EQ(2u, result_tabs->GetSize()); | 96 EXPECT_EQ(2u, result_tabs->GetSize()); |
97 for (size_t i = 0; i < result_tabs->GetSize(); ++i) { | 97 for (size_t i = 0; i < result_tabs->GetSize(); ++i) { |
98 DictionaryValue* result_tab = NULL; | 98 base::DictionaryValue* result_tab = NULL; |
99 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); | 99 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); |
100 EXPECT_EQ(focused_window_id, utils::GetInteger(result_tab, | 100 EXPECT_EQ(focused_window_id, utils::GetInteger(result_tab, |
101 keys::kWindowIdKey)); | 101 keys::kWindowIdKey)); |
102 } | 102 } |
103 | 103 |
104 // Get tabs NOT in the 'last focused' window called from the focused browser. | 104 // Get tabs NOT in the 'last focused' window called from the focused browser. |
105 function = new extensions::TabsQueryFunction(); | 105 function = new extensions::TabsQueryFunction(); |
106 result.reset(utils::ToList( | 106 result.reset(utils::ToList( |
107 utils::RunFunctionAndReturnSingleResult(function.get(), | 107 utils::RunFunctionAndReturnSingleResult(function.get(), |
108 "[{\"lastFocusedWindow\":false}]", | 108 "[{\"lastFocusedWindow\":false}]", |
109 browser()))); | 109 browser()))); |
110 | 110 |
111 result_tabs = result.get(); | 111 result_tabs = result.get(); |
112 // We should get one tab for each extra window and one for the initial window. | 112 // We should get one tab for each extra window and one for the initial window. |
113 EXPECT_EQ(kExtraWindows + 1, result_tabs->GetSize()); | 113 EXPECT_EQ(kExtraWindows + 1, result_tabs->GetSize()); |
114 for (size_t i = 0; i < result_tabs->GetSize(); ++i) { | 114 for (size_t i = 0; i < result_tabs->GetSize(); ++i) { |
115 DictionaryValue* result_tab = NULL; | 115 base::DictionaryValue* result_tab = NULL; |
116 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); | 116 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); |
117 EXPECT_NE(focused_window_id, utils::GetInteger(result_tab, | 117 EXPECT_NE(focused_window_id, utils::GetInteger(result_tab, |
118 keys::kWindowIdKey)); | 118 keys::kWindowIdKey)); |
119 } | 119 } |
120 } | 120 } |
121 | 121 |
122 #if defined(OS_WIN) // http://crbug.com/154081 && http://crbug.com/171080 | 122 #if defined(OS_WIN) // http://crbug.com/154081 && http://crbug.com/171080 |
123 #define MAYBE_TabCurrentWindow DISABLED_TabCurrentWindow | 123 #define MAYBE_TabCurrentWindow DISABLED_TabCurrentWindow |
124 #else | 124 #else |
125 #define MAYBE_TabCurrentWindow TabCurrentWindow | 125 #define MAYBE_TabCurrentWindow TabCurrentWindow |
126 #endif | 126 #endif |
127 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_TabCurrentWindow) { | 127 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_TabCurrentWindow) { |
128 ASSERT_TRUE(RunExtensionTest("tabs/current_window")) << message_; | 128 ASSERT_TRUE(RunExtensionTest("tabs/current_window")) << message_; |
129 } | 129 } |
OLD | NEW |