Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(508)

Side by Side Diff: chrome/browser/extensions/api/tabs/tabs_test.cc

Issue 11747025: Run the JSON Schema Compiler's bundle compilation on JSON files. Previously it (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix ms release build Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
7 #include <string> 6 #include <string>
8 7
9 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/string_util.h"
11 #include "base/stringprintf.h" 11 #include "base/stringprintf.h"
12 #include "base/string_util.h"
13 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/extensions/api/tabs/tabs_api.h"
14 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" 14 #include "chrome/browser/extensions/api/tabs/tabs_constants.h"
15 #include "chrome/browser/extensions/extension_function_test_utils.h" 15 #include "chrome/browser/extensions/extension_function_test_utils.h"
16 #include "chrome/browser/extensions/extension_tab_util.h" 16 #include "chrome/browser/extensions/extension_tab_util.h"
17 #include "chrome/browser/prefs/incognito_mode_prefs.h" 17 #include "chrome/browser/prefs/incognito_mode_prefs.h"
18 #include "chrome/browser/prefs/pref_service.h" 18 #include "chrome/browser/prefs/pref_service.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_commands.h" 21 #include "chrome/browser/ui/browser_commands.h"
22 #include "chrome/browser/ui/browser_window.h" 22 #include "chrome/browser/ui/browser_window.h"
23 #include "chrome/test/base/in_process_browser_test.h" 23 #include "chrome/test/base/in_process_browser_test.h"
24 #include "chrome/test/base/ui_test_utils.h" 24 #include "chrome/test/base/ui_test_utils.h"
25 #include "ui/gfx/rect.h" 25 #include "ui/gfx/rect.h"
26 26
27 namespace keys = extensions::tabs_constants; 27 namespace keys = extensions::tabs_constants;
28 namespace utils = extension_function_test_utils; 28 namespace utils = extension_function_test_utils;
29 29
30 namespace { 30 namespace {
31 31
32 class ExtensionTabsTest : public InProcessBrowserTest { 32 class ExtensionTabsTest : public InProcessBrowserTest {
33 }; 33 };
34 34
35 } 35 }
36 36
37 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetWindow) { 37 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetWindow) {
38 int window_id = ExtensionTabUtil::GetWindowId(browser()); 38 int window_id = ExtensionTabUtil::GetWindowId(browser());
39 39
40 // Invalid window ID error. 40 // Invalid window ID error.
41 scoped_refptr<GetWindowFunction> function = new GetWindowFunction(); 41 scoped_refptr<WindowsGetFunction> function = new WindowsGetFunction();
42 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension()); 42 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension());
43 function->set_extension(extension.get()); 43 function->set_extension(extension.get());
44 EXPECT_TRUE(MatchPattern( 44 EXPECT_TRUE(MatchPattern(
45 utils::RunFunctionAndReturnError( 45 utils::RunFunctionAndReturnError(
46 function.get(), 46 function.get(),
47 base::StringPrintf("[%u]", window_id + 1), 47 base::StringPrintf("[%u]", window_id + 1),
48 browser()), 48 browser()),
49 keys::kWindowNotFoundError)); 49 keys::kWindowNotFoundError));
50 50
51 // Basic window details. 51 // Basic window details.
52 gfx::Rect bounds; 52 gfx::Rect bounds;
53 if (browser()->window()->IsMinimized()) 53 if (browser()->window()->IsMinimized())
54 bounds = browser()->window()->GetRestoredBounds(); 54 bounds = browser()->window()->GetRestoredBounds();
55 else 55 else
56 bounds = browser()->window()->GetBounds(); 56 bounds = browser()->window()->GetBounds();
57 57
58 function = new GetWindowFunction(); 58 function = new WindowsGetFunction();
59 function->set_extension(extension.get()); 59 function->set_extension(extension.get());
60 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( 60 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary(
61 utils::RunFunctionAndReturnSingleResult( 61 utils::RunFunctionAndReturnSingleResult(
62 function.get(), 62 function.get(),
63 base::StringPrintf("[%u]", window_id), 63 base::StringPrintf("[%u]", window_id),
64 browser()))); 64 browser())));
65 EXPECT_EQ(window_id, utils::GetInteger(result.get(), "id")); 65 EXPECT_EQ(window_id, utils::GetInteger(result.get(), "id"));
66 EXPECT_FALSE(utils::GetBoolean(result.get(), "incognito")); 66 EXPECT_FALSE(utils::GetBoolean(result.get(), "incognito"));
67 EXPECT_EQ("normal", utils::GetString(result.get(), "type")); 67 EXPECT_EQ("normal", utils::GetString(result.get(), "type"));
68 EXPECT_EQ(bounds.x(), utils::GetInteger(result.get(), "left")); 68 EXPECT_EQ(bounds.x(), utils::GetInteger(result.get(), "left"));
69 EXPECT_EQ(bounds.y(), utils::GetInteger(result.get(), "top")); 69 EXPECT_EQ(bounds.y(), utils::GetInteger(result.get(), "top"));
70 EXPECT_EQ(bounds.width(), utils::GetInteger(result.get(), "width")); 70 EXPECT_EQ(bounds.width(), utils::GetInteger(result.get(), "width"));
71 EXPECT_EQ(bounds.height(), utils::GetInteger(result.get(), "height")); 71 EXPECT_EQ(bounds.height(), utils::GetInteger(result.get(), "height"));
72 72
73 // With "populate" enabled. 73 // With "populate" enabled.
74 function = new GetWindowFunction(); 74 function = new WindowsGetFunction();
75 function->set_extension(extension.get()); 75 function->set_extension(extension.get());
76 result.reset(utils::ToDictionary( 76 result.reset(utils::ToDictionary(
77 utils::RunFunctionAndReturnSingleResult( 77 utils::RunFunctionAndReturnSingleResult(
78 function.get(), 78 function.get(),
79 base::StringPrintf("[%u, {\"populate\": true}]", window_id), 79 base::StringPrintf("[%u, {\"populate\": true}]", window_id),
80 browser()))); 80 browser())));
81 81
82 EXPECT_EQ(window_id, utils::GetInteger(result.get(), "id")); 82 EXPECT_EQ(window_id, utils::GetInteger(result.get(), "id"));
83 // "populate" was enabled so tabs should be populated. 83 // "populate" was enabled so tabs should be populated.
84 ListValue* tabs = NULL; 84 ListValue* tabs = NULL;
85 EXPECT_TRUE(result.get()->GetList(keys::kTabsKey, &tabs)); 85 EXPECT_TRUE(result.get()->GetList(keys::kTabsKey, &tabs));
86 86
87 // TODO(aa): Can't assume window is focused. On mac, calling Activate() from a 87 // TODO(aa): Can't assume window is focused. On mac, calling Activate() from a
88 // browser test doesn't seem to do anything, so can't test the opposite 88 // browser test doesn't seem to do anything, so can't test the opposite
89 // either. 89 // either.
90 EXPECT_EQ(browser()->window()->IsActive(), 90 EXPECT_EQ(browser()->window()->IsActive(),
91 utils::GetBoolean(result.get(), "focused")); 91 utils::GetBoolean(result.get(), "focused"));
92 92
93 // TODO(aa): Minimized and maximized dimensions. Is there a way to set 93 // TODO(aa): Minimized and maximized dimensions. Is there a way to set
94 // minimize/maximize programmatically? 94 // minimize/maximize programmatically?
95 95
96 // Popup. 96 // Popup.
97 Browser* popup_browser = new Browser( 97 Browser* popup_browser = new Browser(
98 Browser::CreateParams(Browser::TYPE_POPUP, browser()->profile())); 98 Browser::CreateParams(Browser::TYPE_POPUP, browser()->profile()));
99 function = new GetWindowFunction(); 99 function = new WindowsGetFunction();
100 function->set_extension(extension.get()); 100 function->set_extension(extension.get());
101 result.reset(utils::ToDictionary( 101 result.reset(utils::ToDictionary(
102 utils::RunFunctionAndReturnSingleResult( 102 utils::RunFunctionAndReturnSingleResult(
103 function.get(), 103 function.get(),
104 base::StringPrintf( 104 base::StringPrintf(
105 "[%u]", ExtensionTabUtil::GetWindowId(popup_browser)), 105 "[%u]", ExtensionTabUtil::GetWindowId(popup_browser)),
106 browser()))); 106 browser())));
107 EXPECT_EQ("popup", utils::GetString(result.get(), "type")); 107 EXPECT_EQ("popup", utils::GetString(result.get(), "type"));
108 108
109 // Panel. 109 // Panel.
110 Browser* panel_browser = new Browser( 110 Browser* panel_browser = new Browser(
111 Browser::CreateParams(Browser::TYPE_PANEL, browser()->profile())); 111 Browser::CreateParams(Browser::TYPE_PANEL, browser()->profile()));
112 function = new GetWindowFunction(); 112 function = new WindowsGetFunction();
113 function->set_extension(extension.get()); 113 function->set_extension(extension.get());
114 result.reset(utils::ToDictionary( 114 result.reset(utils::ToDictionary(
115 utils::RunFunctionAndReturnSingleResult( 115 utils::RunFunctionAndReturnSingleResult(
116 function.get(), 116 function.get(),
117 base::StringPrintf( 117 base::StringPrintf(
118 "[%u]", ExtensionTabUtil::GetWindowId(panel_browser)), 118 "[%u]", ExtensionTabUtil::GetWindowId(panel_browser)),
119 browser()))); 119 browser())));
120 EXPECT_EQ("panel", utils::GetString(result.get(), "type")); 120 EXPECT_EQ("panel", utils::GetString(result.get(), "type"));
121 121
122 // Incognito. 122 // Incognito.
123 Browser* incognito_browser = CreateIncognitoBrowser(); 123 Browser* incognito_browser = CreateIncognitoBrowser();
124 int incognito_window_id = ExtensionTabUtil::GetWindowId(incognito_browser); 124 int incognito_window_id = ExtensionTabUtil::GetWindowId(incognito_browser);
125 125
126 // Without "include_incognito". 126 // Without "include_incognito".
127 function = new GetWindowFunction(); 127 function = new WindowsGetFunction();
128 function->set_extension(extension.get()); 128 function->set_extension(extension.get());
129 EXPECT_TRUE(MatchPattern( 129 EXPECT_TRUE(MatchPattern(
130 utils::RunFunctionAndReturnError( 130 utils::RunFunctionAndReturnError(
131 function.get(), 131 function.get(),
132 base::StringPrintf("[%u]", incognito_window_id), 132 base::StringPrintf("[%u]", incognito_window_id),
133 browser()), 133 browser()),
134 keys::kWindowNotFoundError)); 134 keys::kWindowNotFoundError));
135 135
136 // With "include_incognito". 136 // With "include_incognito".
137 function = new GetWindowFunction(); 137 function = new WindowsGetFunction();
138 function->set_extension(extension.get()); 138 function->set_extension(extension.get());
139 result.reset(utils::ToDictionary( 139 result.reset(utils::ToDictionary(
140 utils::RunFunctionAndReturnSingleResult( 140 utils::RunFunctionAndReturnSingleResult(
141 function.get(), 141 function.get(),
142 base::StringPrintf("[%u]", incognito_window_id), 142 base::StringPrintf("[%u]", incognito_window_id),
143 browser(), 143 browser(),
144 utils::INCLUDE_INCOGNITO))); 144 utils::INCLUDE_INCOGNITO)));
145 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito")); 145 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito"));
146 } 146 }
147 147
148 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetCurrentWindow) { 148 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetCurrentWindow) {
149 int window_id = ExtensionTabUtil::GetWindowId(browser()); 149 int window_id = ExtensionTabUtil::GetWindowId(browser());
150 Browser* new_browser = CreateBrowser(browser()->profile()); 150 Browser* new_browser = CreateBrowser(browser()->profile());
151 int new_id = ExtensionTabUtil::GetWindowId(new_browser); 151 int new_id = ExtensionTabUtil::GetWindowId(new_browser);
152 152
153 // Get the current window using new_browser. 153 // Get the current window using new_browser.
154 scoped_refptr<GetCurrentWindowFunction> function = 154 scoped_refptr<WindowsGetCurrentFunction> function =
155 new GetCurrentWindowFunction(); 155 new WindowsGetCurrentFunction();
156 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension()); 156 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension());
157 function->set_extension(extension.get()); 157 function->set_extension(extension.get());
158 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( 158 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary(
159 utils::RunFunctionAndReturnSingleResult(function.get(), 159 utils::RunFunctionAndReturnSingleResult(function.get(),
160 "[]", 160 "[]",
161 new_browser))); 161 new_browser)));
162 162
163 // The id should match the window id of the browser instance that was passed 163 // The id should match the window id of the browser instance that was passed
164 // to RunFunctionAndReturnSingleResult. 164 // to RunFunctionAndReturnSingleResult.
165 EXPECT_EQ(new_id, utils::GetInteger(result.get(), "id")); 165 EXPECT_EQ(new_id, utils::GetInteger(result.get(), "id"));
166 ListValue* tabs = NULL; 166 ListValue* tabs = NULL;
167 EXPECT_FALSE(result.get()->GetList(keys::kTabsKey, &tabs)); 167 EXPECT_FALSE(result.get()->GetList(keys::kTabsKey, &tabs));
168 168
169 // Get the current window using the old window and make the tabs populated. 169 // Get the current window using the old window and make the tabs populated.
170 function = new GetCurrentWindowFunction(); 170 function = new WindowsGetCurrentFunction();
171 function->set_extension(extension.get()); 171 function->set_extension(extension.get());
172 result.reset(utils::ToDictionary( 172 result.reset(utils::ToDictionary(
173 utils::RunFunctionAndReturnSingleResult(function.get(), 173 utils::RunFunctionAndReturnSingleResult(function.get(),
174 "[{\"populate\": true}]", 174 "[{\"populate\": true}]",
175 browser()))); 175 browser())));
176 176
177 // The id should match the window id of the browser instance that was passed 177 // The id should match the window id of the browser instance that was passed
178 // to RunFunctionAndReturnSingleResult. 178 // to RunFunctionAndReturnSingleResult.
179 EXPECT_EQ(window_id, utils::GetInteger(result.get(), "id")); 179 EXPECT_EQ(window_id, utils::GetInteger(result.get(), "id"));
180 // "populate" was enabled so tabs should be populated. 180 // "populate" was enabled so tabs should be populated.
181 EXPECT_TRUE(result.get()->GetList(keys::kTabsKey, &tabs)); 181 EXPECT_TRUE(result.get()->GetList(keys::kTabsKey, &tabs));
182 } 182 }
183 183
184 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetAllWindows) { 184 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetAllWindows) {
185 const size_t NUM_WINDOWS = 5; 185 const size_t NUM_WINDOWS = 5;
186 std::set<int> window_ids; 186 std::set<int> window_ids;
187 std::set<int> result_ids; 187 std::set<int> result_ids;
188 window_ids.insert(ExtensionTabUtil::GetWindowId(browser())); 188 window_ids.insert(ExtensionTabUtil::GetWindowId(browser()));
189 189
190 for (size_t i = 0; i < NUM_WINDOWS - 1; ++i) { 190 for (size_t i = 0; i < NUM_WINDOWS - 1; ++i) {
191 Browser* new_browser = CreateBrowser(browser()->profile()); 191 Browser* new_browser = CreateBrowser(browser()->profile());
192 window_ids.insert(ExtensionTabUtil::GetWindowId(new_browser)); 192 window_ids.insert(ExtensionTabUtil::GetWindowId(new_browser));
193 } 193 }
194 194
195 scoped_refptr<GetAllWindowsFunction> function = new GetAllWindowsFunction(); 195 scoped_refptr<WindowsGetAllFunction> function = new WindowsGetAllFunction();
196 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension()); 196 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension());
197 function->set_extension(extension.get()); 197 function->set_extension(extension.get());
198 scoped_ptr<base::ListValue> result(utils::ToList( 198 scoped_ptr<base::ListValue> result(utils::ToList(
199 utils::RunFunctionAndReturnSingleResult(function.get(), 199 utils::RunFunctionAndReturnSingleResult(function.get(),
200 "[]", 200 "[]",
201 browser()))); 201 browser())));
202 202
203 ListValue* windows = result.get(); 203 ListValue* windows = result.get();
204 EXPECT_EQ(NUM_WINDOWS, windows->GetSize()); 204 EXPECT_EQ(NUM_WINDOWS, windows->GetSize());
205 for (size_t i = 0; i < NUM_WINDOWS; ++i) { 205 for (size_t i = 0; i < NUM_WINDOWS; ++i) {
206 DictionaryValue* result_window = NULL; 206 DictionaryValue* result_window = NULL;
207 EXPECT_TRUE(windows->GetDictionary(i, &result_window)); 207 EXPECT_TRUE(windows->GetDictionary(i, &result_window));
208 result_ids.insert(utils::GetInteger(result_window, "id")); 208 result_ids.insert(utils::GetInteger(result_window, "id"));
209 209
210 // "populate" was not passed in so tabs are not populated. 210 // "populate" was not passed in so tabs are not populated.
211 ListValue* tabs = NULL; 211 ListValue* tabs = NULL;
212 EXPECT_FALSE(result_window->GetList(keys::kTabsKey, &tabs)); 212 EXPECT_FALSE(result_window->GetList(keys::kTabsKey, &tabs));
213 } 213 }
214 // The returned ids should contain all the current browser instance ids. 214 // The returned ids should contain all the current browser instance ids.
215 EXPECT_EQ(window_ids, result_ids); 215 EXPECT_EQ(window_ids, result_ids);
216 216
217 result_ids.clear(); 217 result_ids.clear();
218 function = new GetAllWindowsFunction(); 218 function = new WindowsGetAllFunction();
219 function->set_extension(extension.get()); 219 function->set_extension(extension.get());
220 result.reset(utils::ToList( 220 result.reset(utils::ToList(
221 utils::RunFunctionAndReturnSingleResult(function.get(), 221 utils::RunFunctionAndReturnSingleResult(function.get(),
222 "[{\"populate\": true}]", 222 "[{\"populate\": true}]",
223 browser()))); 223 browser())));
224 224
225 windows = result.get(); 225 windows = result.get();
226 EXPECT_EQ(NUM_WINDOWS, windows->GetSize()); 226 EXPECT_EQ(NUM_WINDOWS, windows->GetSize());
227 for (size_t i = 0; i < windows->GetSize(); ++i) { 227 for (size_t i = 0; i < windows->GetSize(); ++i) {
228 DictionaryValue* result_window = NULL; 228 DictionaryValue* result_window = NULL;
229 EXPECT_TRUE(windows->GetDictionary(i, &result_window)); 229 EXPECT_TRUE(windows->GetDictionary(i, &result_window));
230 result_ids.insert(utils::GetInteger(result_window, "id")); 230 result_ids.insert(utils::GetInteger(result_window, "id"));
231 231
232 // "populate" was enabled so tabs should be populated. 232 // "populate" was enabled so tabs should be populated.
233 ListValue* tabs = NULL; 233 ListValue* tabs = NULL;
234 EXPECT_TRUE(result_window->GetList(keys::kTabsKey, &tabs)); 234 EXPECT_TRUE(result_window->GetList(keys::kTabsKey, &tabs));
235 } 235 }
236 // The returned ids should contain all the current browser instance ids. 236 // The returned ids should contain all the current browser instance ids.
237 EXPECT_EQ(window_ids, result_ids); 237 EXPECT_EQ(window_ids, result_ids);
238 } 238 }
239 239
240 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, UpdateNoPermissions) { 240 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, UpdateNoPermissions) {
241 // The test empty extension has no permissions, therefore it should not get 241 // The test empty extension has no permissions, therefore it should not get
242 // tab data in the function result. 242 // tab data in the function result.
243 scoped_refptr<UpdateTabFunction> update_tab_function(new UpdateTabFunction()); 243 scoped_refptr<TabsUpdateFunction> update_tab_function(
244 new TabsUpdateFunction());
244 scoped_refptr<extensions::Extension> empty_extension( 245 scoped_refptr<extensions::Extension> empty_extension(
245 utils::CreateEmptyExtension()); 246 utils::CreateEmptyExtension());
246 update_tab_function->set_extension(empty_extension.get()); 247 update_tab_function->set_extension(empty_extension.get());
247 // Without a callback the function will not generate a result. 248 // Without a callback the function will not generate a result.
248 update_tab_function->set_has_callback(true); 249 update_tab_function->set_has_callback(true);
249 250
250 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( 251 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary(
251 utils::RunFunctionAndReturnSingleResult( 252 utils::RunFunctionAndReturnSingleResult(
252 update_tab_function.get(), 253 update_tab_function.get(),
253 "[null, {\"url\": \"about:blank\", \"pinned\": true}]", 254 "[null, {\"url\": \"about:blank\", \"pinned\": true}]",
254 browser()))); 255 browser())));
255 // The url is stripped since the extension does not have tab permissions. 256 // The url is stripped since the extension does not have tab permissions.
256 EXPECT_FALSE(result->HasKey("url")); 257 EXPECT_FALSE(result->HasKey("url"));
257 EXPECT_TRUE(utils::GetBoolean(result.get(), "pinned")); 258 EXPECT_TRUE(utils::GetBoolean(result.get(), "pinned"));
258 } 259 }
259 260
260 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, 261 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest,
261 DefaultToIncognitoWhenItIsForced) { 262 DefaultToIncognitoWhenItIsForced) {
262 static const char kArgsWithoutExplicitIncognitoParam[] = 263 static const char kArgsWithoutExplicitIncognitoParam[] =
263 "[{\"url\": \"about:blank\"}]"; 264 "[{\"url\": \"about:blank\"}]";
264 // Force Incognito mode. 265 // Force Incognito mode.
265 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), 266 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(),
266 IncognitoModePrefs::FORCED); 267 IncognitoModePrefs::FORCED);
267 // Run without an explicit "incognito" param. 268 // Run without an explicit "incognito" param.
268 scoped_refptr<CreateWindowFunction> function(new CreateWindowFunction()); 269 scoped_refptr<WindowsCreateFunction> function(new WindowsCreateFunction());
269 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension()); 270 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension());
270 function->set_extension(extension.get()); 271 function->set_extension(extension.get());
271 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( 272 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary(
272 utils::RunFunctionAndReturnSingleResult( 273 utils::RunFunctionAndReturnSingleResult(
273 function.get(), 274 function.get(),
274 kArgsWithoutExplicitIncognitoParam, 275 kArgsWithoutExplicitIncognitoParam,
275 browser(), 276 browser(),
276 utils::INCLUDE_INCOGNITO))); 277 utils::INCLUDE_INCOGNITO)));
277 278
278 // Make sure it is a new(different) window. 279 // Make sure it is a new(different) window.
279 EXPECT_NE(ExtensionTabUtil::GetWindowId(browser()), 280 EXPECT_NE(ExtensionTabUtil::GetWindowId(browser()),
280 utils::GetInteger(result.get(), "id")); 281 utils::GetInteger(result.get(), "id"));
281 // ... and it is incognito. 282 // ... and it is incognito.
282 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito")); 283 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito"));
283 284
284 // Now try creating a window from incognito window. 285 // Now try creating a window from incognito window.
285 Browser* incognito_browser = CreateIncognitoBrowser(); 286 Browser* incognito_browser = CreateIncognitoBrowser();
286 // Run without an explicit "incognito" param. 287 // Run without an explicit "incognito" param.
287 function = new CreateWindowFunction(); 288 function = new WindowsCreateFunction();
288 function->set_extension(extension.get()); 289 function->set_extension(extension.get());
289 result.reset(utils::ToDictionary( 290 result.reset(utils::ToDictionary(
290 utils::RunFunctionAndReturnSingleResult( 291 utils::RunFunctionAndReturnSingleResult(
291 function.get(), 292 function.get(),
292 kArgsWithoutExplicitIncognitoParam, 293 kArgsWithoutExplicitIncognitoParam,
293 incognito_browser, 294 incognito_browser,
294 utils::INCLUDE_INCOGNITO))); 295 utils::INCLUDE_INCOGNITO)));
295 // Make sure it is a new(different) window. 296 // Make sure it is a new(different) window.
296 EXPECT_NE(ExtensionTabUtil::GetWindowId(incognito_browser), 297 EXPECT_NE(ExtensionTabUtil::GetWindowId(incognito_browser),
297 utils::GetInteger(result.get(), "id")); 298 utils::GetInteger(result.get(), "id"));
298 // ... and it is incognito. 299 // ... and it is incognito.
299 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito")); 300 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito"));
300 } 301 }
301 302
302 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, 303 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest,
303 DefaultToIncognitoWhenItIsForcedAndNoArgs) { 304 DefaultToIncognitoWhenItIsForcedAndNoArgs) {
304 static const char kEmptyArgs[] = "[]"; 305 static const char kEmptyArgs[] = "[]";
305 // Force Incognito mode. 306 // Force Incognito mode.
306 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), 307 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(),
307 IncognitoModePrefs::FORCED); 308 IncognitoModePrefs::FORCED);
308 // Run without an explicit "incognito" param. 309 // Run without an explicit "incognito" param.
309 scoped_refptr<CreateWindowFunction> function = new CreateWindowFunction(); 310 scoped_refptr<WindowsCreateFunction> function = new WindowsCreateFunction();
310 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension()); 311 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension());
311 function->set_extension(extension.get()); 312 function->set_extension(extension.get());
312 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( 313 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary(
313 utils::RunFunctionAndReturnSingleResult(function.get(), 314 utils::RunFunctionAndReturnSingleResult(function.get(),
314 kEmptyArgs, 315 kEmptyArgs,
315 browser(), 316 browser(),
316 utils::INCLUDE_INCOGNITO))); 317 utils::INCLUDE_INCOGNITO)));
317 318
318 // Make sure it is a new(different) window. 319 // Make sure it is a new(different) window.
319 EXPECT_NE(ExtensionTabUtil::GetWindowId(browser()), 320 EXPECT_NE(ExtensionTabUtil::GetWindowId(browser()),
320 utils::GetInteger(result.get(), "id")); 321 utils::GetInteger(result.get(), "id"));
321 // ... and it is incognito. 322 // ... and it is incognito.
322 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito")); 323 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito"));
323 324
324 // Now try creating a window from incognito window. 325 // Now try creating a window from incognito window.
325 Browser* incognito_browser = CreateIncognitoBrowser(); 326 Browser* incognito_browser = CreateIncognitoBrowser();
326 // Run without an explicit "incognito" param. 327 // Run without an explicit "incognito" param.
327 function = new CreateWindowFunction(); 328 function = new WindowsCreateFunction();
328 function->set_extension(extension.get()); 329 function->set_extension(extension.get());
329 result.reset(utils::ToDictionary( 330 result.reset(utils::ToDictionary(
330 utils::RunFunctionAndReturnSingleResult(function.get(), 331 utils::RunFunctionAndReturnSingleResult(function.get(),
331 kEmptyArgs, 332 kEmptyArgs,
332 incognito_browser, 333 incognito_browser,
333 utils::INCLUDE_INCOGNITO))); 334 utils::INCLUDE_INCOGNITO)));
334 // Make sure it is a new(different) window. 335 // Make sure it is a new(different) window.
335 EXPECT_NE(ExtensionTabUtil::GetWindowId(incognito_browser), 336 EXPECT_NE(ExtensionTabUtil::GetWindowId(incognito_browser),
336 utils::GetInteger(result.get(), "id")); 337 utils::GetInteger(result.get(), "id"));
337 // ... and it is incognito. 338 // ... and it is incognito.
338 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito")); 339 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito"));
339 } 340 }
340 341
341 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, 342 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest,
342 DontCreateNormalWindowWhenIncognitoForced) { 343 DontCreateNormalWindowWhenIncognitoForced) {
343 static const char kArgsWithExplicitIncognitoParam[] = 344 static const char kArgsWithExplicitIncognitoParam[] =
344 "[{\"url\": \"about:blank\", \"incognito\": false }]"; 345 "[{\"url\": \"about:blank\", \"incognito\": false }]";
345 // Force Incognito mode. 346 // Force Incognito mode.
346 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), 347 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(),
347 IncognitoModePrefs::FORCED); 348 IncognitoModePrefs::FORCED);
348 349
349 // Run with an explicit "incognito" param. 350 // Run with an explicit "incognito" param.
350 scoped_refptr<CreateWindowFunction> function = new CreateWindowFunction(); 351 scoped_refptr<WindowsCreateFunction> function = new WindowsCreateFunction();
351 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension()); 352 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension());
352 function->set_extension(extension.get()); 353 function->set_extension(extension.get());
353 EXPECT_TRUE(MatchPattern( 354 EXPECT_TRUE(MatchPattern(
354 utils::RunFunctionAndReturnError(function.get(), 355 utils::RunFunctionAndReturnError(function.get(),
355 kArgsWithExplicitIncognitoParam, 356 kArgsWithExplicitIncognitoParam,
356 browser()), 357 browser()),
357 keys::kIncognitoModeIsForced)); 358 keys::kIncognitoModeIsForced));
358 359
359 // Now try opening a normal window from incognito window. 360 // Now try opening a normal window from incognito window.
360 Browser* incognito_browser = CreateIncognitoBrowser(); 361 Browser* incognito_browser = CreateIncognitoBrowser();
361 // Run with an explicit "incognito" param. 362 // Run with an explicit "incognito" param.
362 function = new CreateWindowFunction(); 363 function = new WindowsCreateFunction();
363 function->set_extension(extension.get()); 364 function->set_extension(extension.get());
364 EXPECT_TRUE(MatchPattern( 365 EXPECT_TRUE(MatchPattern(
365 utils::RunFunctionAndReturnError(function.get(), 366 utils::RunFunctionAndReturnError(function.get(),
366 kArgsWithExplicitIncognitoParam, 367 kArgsWithExplicitIncognitoParam,
367 incognito_browser), 368 incognito_browser),
368 keys::kIncognitoModeIsForced)); 369 keys::kIncognitoModeIsForced));
369 } 370 }
370 371
371 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, 372 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest,
372 DontCreateIncognitoWindowWhenIncognitoDisabled) { 373 DontCreateIncognitoWindowWhenIncognitoDisabled) {
373 static const char kArgs[] = 374 static const char kArgs[] =
374 "[{\"url\": \"about:blank\", \"incognito\": true }]"; 375 "[{\"url\": \"about:blank\", \"incognito\": true }]";
375 376
376 Browser* incognito_browser = CreateIncognitoBrowser(); 377 Browser* incognito_browser = CreateIncognitoBrowser();
377 // Disable Incognito mode. 378 // Disable Incognito mode.
378 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), 379 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(),
379 IncognitoModePrefs::DISABLED); 380 IncognitoModePrefs::DISABLED);
380 // Run in normal window. 381 // Run in normal window.
381 scoped_refptr<CreateWindowFunction> function = new CreateWindowFunction(); 382 scoped_refptr<WindowsCreateFunction> function = new WindowsCreateFunction();
382 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension()); 383 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension());
383 function->set_extension(extension.get()); 384 function->set_extension(extension.get());
384 EXPECT_TRUE(MatchPattern( 385 EXPECT_TRUE(MatchPattern(
385 utils::RunFunctionAndReturnError(function.get(), 386 utils::RunFunctionAndReturnError(function.get(),
386 kArgs, 387 kArgs,
387 browser()), 388 browser()),
388 keys::kIncognitoModeIsDisabled)); 389 keys::kIncognitoModeIsDisabled));
389 390
390 // Run in incognito window. 391 // Run in incognito window.
391 function = new CreateWindowFunction(); 392 function = new WindowsCreateFunction();
392 function->set_extension(extension.get()); 393 function->set_extension(extension.get());
393 EXPECT_TRUE(MatchPattern( 394 EXPECT_TRUE(MatchPattern(
394 utils::RunFunctionAndReturnError(function.get(), 395 utils::RunFunctionAndReturnError(function.get(),
395 kArgs, 396 kArgs,
396 incognito_browser), 397 incognito_browser),
397 keys::kIncognitoModeIsDisabled)); 398 keys::kIncognitoModeIsDisabled));
398 } 399 }
399 400
400 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, QueryCurrentWindowTabs) { 401 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, QueryCurrentWindowTabs) {
401 const size_t kExtraWindows = 3; 402 const size_t kExtraWindows = 3;
402 for (size_t i = 0; i < kExtraWindows; ++i) 403 for (size_t i = 0; i < kExtraWindows; ++i)
403 CreateBrowser(browser()->profile()); 404 CreateBrowser(browser()->profile());
404 405
405 GURL url; 406 GURL url;
406 AddTabAtIndexToBrowser(browser(), 0, url, content::PAGE_TRANSITION_LINK); 407 AddTabAtIndexToBrowser(browser(), 0, url, content::PAGE_TRANSITION_LINK);
407 int window_id = ExtensionTabUtil::GetWindowId(browser()); 408 int window_id = ExtensionTabUtil::GetWindowId(browser());
408 409
409 // Get tabs in the 'current' window called from non-focused browser. 410 // Get tabs in the 'current' window called from non-focused browser.
410 scoped_refptr<QueryTabsFunction> function = new QueryTabsFunction(); 411 scoped_refptr<TabsQueryFunction> function = new TabsQueryFunction();
411 function->set_extension(utils::CreateEmptyExtension().get()); 412 function->set_extension(utils::CreateEmptyExtension().get());
412 scoped_ptr<base::ListValue> result(utils::ToList( 413 scoped_ptr<base::ListValue> result(utils::ToList(
413 utils::RunFunctionAndReturnSingleResult(function.get(), 414 utils::RunFunctionAndReturnSingleResult(function.get(),
414 "[{\"currentWindow\":true}]", 415 "[{\"currentWindow\":true}]",
415 browser()))); 416 browser())));
416 417
417 ListValue* result_tabs = result.get(); 418 ListValue* result_tabs = result.get();
418 // We should have one initial tab and one added tab. 419 // We should have one initial tab and one added tab.
419 EXPECT_EQ(2u, result_tabs->GetSize()); 420 EXPECT_EQ(2u, result_tabs->GetSize());
420 for (size_t i = 0; i < result_tabs->GetSize(); ++i) { 421 for (size_t i = 0; i < result_tabs->GetSize(); ++i) {
421 DictionaryValue* result_tab = NULL; 422 DictionaryValue* result_tab = NULL;
422 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); 423 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab));
423 EXPECT_EQ(window_id, utils::GetInteger(result_tab, keys::kWindowIdKey)); 424 EXPECT_EQ(window_id, utils::GetInteger(result_tab, keys::kWindowIdKey));
424 } 425 }
425 426
426 // Get tabs NOT in the 'current' window called from non-focused browser. 427 // Get tabs NOT in the 'current' window called from non-focused browser.
427 function = new QueryTabsFunction(); 428 function = new TabsQueryFunction();
428 function->set_extension(utils::CreateEmptyExtension().get()); 429 function->set_extension(utils::CreateEmptyExtension().get());
429 result.reset(utils::ToList( 430 result.reset(utils::ToList(
430 utils::RunFunctionAndReturnSingleResult(function.get(), 431 utils::RunFunctionAndReturnSingleResult(function.get(),
431 "[{\"currentWindow\":false}]", 432 "[{\"currentWindow\":false}]",
432 browser()))); 433 browser())));
433 434
434 result_tabs = result.get(); 435 result_tabs = result.get();
435 // We should have one tab for each extra window. 436 // We should have one tab for each extra window.
436 EXPECT_EQ(kExtraWindows, result_tabs->GetSize()); 437 EXPECT_EQ(kExtraWindows, result_tabs->GetSize());
437 for (size_t i = 0; i < kExtraWindows; ++i) { 438 for (size_t i = 0; i < kExtraWindows; ++i) {
438 DictionaryValue* result_tab = NULL; 439 DictionaryValue* result_tab = NULL;
439 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); 440 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab));
440 EXPECT_NE(window_id, utils::GetInteger(result_tab, keys::kWindowIdKey)); 441 EXPECT_NE(window_id, utils::GetInteger(result_tab, keys::kWindowIdKey));
441 } 442 }
442 } 443 }
443 444
444 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DontCreateTabInClosingPopupWindow) { 445 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DontCreateTabInClosingPopupWindow) {
445 // Test creates new popup window, closes it right away and then tries to open 446 // Test creates new popup window, closes it right away and then tries to open
446 // a new tab in it. Tab should not be opened in the popup window, but in a 447 // a new tab in it. Tab should not be opened in the popup window, but in a
447 // tabbed browser window. 448 // tabbed browser window.
448 Browser* popup_browser = new Browser( 449 Browser* popup_browser = new Browser(
449 Browser::CreateParams(Browser::TYPE_POPUP, browser()->profile())); 450 Browser::CreateParams(Browser::TYPE_POPUP, browser()->profile()));
450 int window_id = ExtensionTabUtil::GetWindowId(popup_browser); 451 int window_id = ExtensionTabUtil::GetWindowId(popup_browser);
451 chrome::CloseWindow(popup_browser); 452 chrome::CloseWindow(popup_browser);
452 453
453 scoped_refptr<CreateTabFunction> create_tab_function(new CreateTabFunction()); 454 scoped_refptr<TabsCreateFunction> create_tab_function(
455 new TabsCreateFunction());
454 create_tab_function->set_extension(utils::CreateEmptyExtension().get()); 456 create_tab_function->set_extension(utils::CreateEmptyExtension().get());
455 // Without a callback the function will not generate a result. 457 // Without a callback the function will not generate a result.
456 create_tab_function->set_has_callback(true); 458 create_tab_function->set_has_callback(true);
457 459
458 static const char kNewBlankTabArgs[] = 460 static const char kNewBlankTabArgs[] =
459 "[{\"url\": \"about:blank\", \"windowId\": %u}]"; 461 "[{\"url\": \"about:blank\", \"windowId\": %u}]";
460 462
461 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( 463 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary(
462 utils::RunFunctionAndReturnSingleResult( 464 utils::RunFunctionAndReturnSingleResult(
463 create_tab_function.get(), 465 create_tab_function.get(),
464 base::StringPrintf(kNewBlankTabArgs, window_id), 466 base::StringPrintf(kNewBlankTabArgs, window_id),
465 browser()))); 467 browser())));
466 468
467 EXPECT_NE(window_id, utils::GetInteger(result.get(), "windowId")); 469 EXPECT_NE(window_id, utils::GetInteger(result.get(), "windowId"));
468 } 470 }
469 471
470 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, InvalidUpdateWindowState) { 472 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, InvalidUpdateWindowState) {
471 int window_id = ExtensionTabUtil::GetWindowId(browser()); 473 int window_id = ExtensionTabUtil::GetWindowId(browser());
472 474
473 static const char kArgsMinimizedWithFocus[] = 475 static const char kArgsMinimizedWithFocus[] =
474 "[%u, {\"state\": \"minimized\", \"focused\": true}]"; 476 "[%u, {\"state\": \"minimized\", \"focused\": true}]";
475 scoped_refptr<UpdateWindowFunction> function = new UpdateWindowFunction(); 477 scoped_refptr<WindowsUpdateFunction> function = new WindowsUpdateFunction();
476 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension()); 478 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension());
477 function->set_extension(extension.get()); 479 function->set_extension(extension.get());
478 EXPECT_TRUE(MatchPattern( 480 EXPECT_TRUE(MatchPattern(
479 utils::RunFunctionAndReturnError( 481 utils::RunFunctionAndReturnError(
480 function.get(), 482 function.get(),
481 base::StringPrintf(kArgsMinimizedWithFocus, window_id), 483 base::StringPrintf(kArgsMinimizedWithFocus, window_id),
482 browser()), 484 browser()),
483 keys::kInvalidWindowStateError)); 485 keys::kInvalidWindowStateError));
484 486
485 static const char kArgsMaximizedWithoutFocus[] = 487 static const char kArgsMaximizedWithoutFocus[] =
486 "[%u, {\"state\": \"maximized\", \"focused\": false}]"; 488 "[%u, {\"state\": \"maximized\", \"focused\": false}]";
487 function = new UpdateWindowFunction(); 489 function = new WindowsUpdateFunction();
488 function->set_extension(extension.get()); 490 function->set_extension(extension.get());
489 EXPECT_TRUE(MatchPattern( 491 EXPECT_TRUE(MatchPattern(
490 utils::RunFunctionAndReturnError( 492 utils::RunFunctionAndReturnError(
491 function.get(), 493 function.get(),
492 base::StringPrintf(kArgsMaximizedWithoutFocus, window_id), 494 base::StringPrintf(kArgsMaximizedWithoutFocus, window_id),
493 browser()), 495 browser()),
494 keys::kInvalidWindowStateError)); 496 keys::kInvalidWindowStateError));
495 497
496 static const char kArgsMinimizedWithBounds[] = 498 static const char kArgsMinimizedWithBounds[] =
497 "[%u, {\"state\": \"minimized\", \"width\": 500}]"; 499 "[%u, {\"state\": \"minimized\", \"width\": 500}]";
498 function = new UpdateWindowFunction(); 500 function = new WindowsUpdateFunction();
499 function->set_extension(extension.get()); 501 function->set_extension(extension.get());
500 EXPECT_TRUE(MatchPattern( 502 EXPECT_TRUE(MatchPattern(
501 utils::RunFunctionAndReturnError( 503 utils::RunFunctionAndReturnError(
502 function.get(), 504 function.get(),
503 base::StringPrintf(kArgsMinimizedWithBounds, window_id), 505 base::StringPrintf(kArgsMinimizedWithBounds, window_id),
504 browser()), 506 browser()),
505 keys::kInvalidWindowStateError)); 507 keys::kInvalidWindowStateError));
506 508
507 static const char kArgsMaximizedWithBounds[] = 509 static const char kArgsMaximizedWithBounds[] =
508 "[%u, {\"state\": \"maximized\", \"width\": 500}]"; 510 "[%u, {\"state\": \"maximized\", \"width\": 500}]";
509 function = new UpdateWindowFunction(); 511 function = new WindowsUpdateFunction();
510 function->set_extension(extension.get()); 512 function->set_extension(extension.get());
511 EXPECT_TRUE(MatchPattern( 513 EXPECT_TRUE(MatchPattern(
512 utils::RunFunctionAndReturnError( 514 utils::RunFunctionAndReturnError(
513 function.get(), 515 function.get(),
514 base::StringPrintf(kArgsMaximizedWithBounds, window_id), 516 base::StringPrintf(kArgsMaximizedWithBounds, window_id),
515 browser()), 517 browser()),
516 keys::kInvalidWindowStateError)); 518 keys::kInvalidWindowStateError));
517 } 519 }
518 520
519 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DuplicateTab) { 521 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DuplicateTab) {
520 static const char kNewBlankTabArgs[] ="about:blank"; 522 static const char kNewBlankTabArgs[] ="about:blank";
521 523
522 content::OpenURLParams params(GURL(kNewBlankTabArgs), content::Referrer(), 524 content::OpenURLParams params(GURL(kNewBlankTabArgs), content::Referrer(),
523 NEW_FOREGROUND_TAB, 525 NEW_FOREGROUND_TAB,
524 content::PAGE_TRANSITION_LINK, false); 526 content::PAGE_TRANSITION_LINK, false);
525 content::WebContents* web_contents = browser()->OpenURL(params); 527 content::WebContents* web_contents = browser()->OpenURL(params);
526 int tab_id = ExtensionTabUtil::GetTabId(web_contents); 528 int tab_id = ExtensionTabUtil::GetTabId(web_contents);
527 int window_id = ExtensionTabUtil::GetWindowIdOfTab(web_contents); 529 int window_id = ExtensionTabUtil::GetWindowIdOfTab(web_contents);
528 int tab_index = -1; 530 int tab_index = -1;
529 TabStripModel* tab_strip; 531 TabStripModel* tab_strip;
530 ExtensionTabUtil::GetTabStripModel(web_contents, &tab_strip, &tab_index); 532 ExtensionTabUtil::GetTabStripModel(web_contents, &tab_strip, &tab_index);
531 533
532 scoped_refptr<DuplicateTabFunction> duplicate_tab_function( 534 scoped_refptr<TabsDuplicateFunction> duplicate_tab_function(
533 new DuplicateTabFunction()); 535 new TabsDuplicateFunction());
534 scoped_ptr<base::DictionaryValue> test_extension_value( 536 scoped_ptr<base::DictionaryValue> test_extension_value(
535 utils::ParseDictionary( 537 utils::ParseDictionary(
536 "{\"name\": \"Test\", \"version\": \"1.0\", \"permissions\": [\"tabs\"]}" 538 "{\"name\": \"Test\", \"version\": \"1.0\", \"permissions\": [\"tabs\"]}"
537 )); 539 ));
538 scoped_refptr<extensions::Extension> empty_tab_extension( 540 scoped_refptr<extensions::Extension> empty_tab_extension(
539 utils::CreateExtension(test_extension_value.get())); 541 utils::CreateExtension(test_extension_value.get()));
540 duplicate_tab_function->set_extension(empty_tab_extension.get()); 542 duplicate_tab_function->set_extension(empty_tab_extension.get());
541 duplicate_tab_function->set_has_callback(true); 543 duplicate_tab_function->set_has_callback(true);
542 544
543 scoped_ptr<base::DictionaryValue> duplicate_result(utils::ToDictionary( 545 scoped_ptr<base::DictionaryValue> duplicate_result(utils::ToDictionary(
(...skipping 22 matching lines...) Expand all
566 content::OpenURLParams params(GURL(kNewBlankTabArgs), content::Referrer(), 568 content::OpenURLParams params(GURL(kNewBlankTabArgs), content::Referrer(),
567 NEW_FOREGROUND_TAB, 569 NEW_FOREGROUND_TAB,
568 content::PAGE_TRANSITION_LINK, false); 570 content::PAGE_TRANSITION_LINK, false);
569 content::WebContents* web_contents = browser()->OpenURL(params); 571 content::WebContents* web_contents = browser()->OpenURL(params);
570 int tab_id = ExtensionTabUtil::GetTabId(web_contents); 572 int tab_id = ExtensionTabUtil::GetTabId(web_contents);
571 int window_id = ExtensionTabUtil::GetWindowIdOfTab(web_contents); 573 int window_id = ExtensionTabUtil::GetWindowIdOfTab(web_contents);
572 int tab_index = -1; 574 int tab_index = -1;
573 TabStripModel* tab_strip; 575 TabStripModel* tab_strip;
574 ExtensionTabUtil::GetTabStripModel(web_contents, &tab_strip, &tab_index); 576 ExtensionTabUtil::GetTabStripModel(web_contents, &tab_strip, &tab_index);
575 577
576 scoped_refptr<DuplicateTabFunction> duplicate_tab_function( 578 scoped_refptr<TabsDuplicateFunction> duplicate_tab_function(
577 new DuplicateTabFunction()); 579 new TabsDuplicateFunction());
578 scoped_refptr<extensions::Extension> empty_extension( 580 scoped_refptr<extensions::Extension> empty_extension(
579 utils::CreateEmptyExtension()); 581 utils::CreateEmptyExtension());
580 duplicate_tab_function->set_extension(empty_extension.get()); 582 duplicate_tab_function->set_extension(empty_extension.get());
581 duplicate_tab_function->set_has_callback(true); 583 duplicate_tab_function->set_has_callback(true);
582 584
583 scoped_ptr<base::DictionaryValue> duplicate_result(utils::ToDictionary( 585 scoped_ptr<base::DictionaryValue> duplicate_result(utils::ToDictionary(
584 utils::RunFunctionAndReturnSingleResult( 586 utils::RunFunctionAndReturnSingleResult(
585 duplicate_tab_function.get(), base::StringPrintf("[%u]", tab_id), 587 duplicate_tab_function.get(), base::StringPrintf("[%u]", tab_id),
586 browser()))); 588 browser())));
587 589
588 int duplicate_tab_id = utils::GetInteger(duplicate_result.get(), "id"); 590 int duplicate_tab_id = utils::GetInteger(duplicate_result.get(), "id");
589 int duplicate_tab_window_id = utils::GetInteger(duplicate_result.get(), 591 int duplicate_tab_window_id = utils::GetInteger(duplicate_result.get(),
590 "windowId"); 592 "windowId");
591 int duplicate_tab_index = utils::GetInteger(duplicate_result.get(), "index"); 593 int duplicate_tab_index = utils::GetInteger(duplicate_result.get(), "index");
592 EXPECT_EQ(base::Value::TYPE_DICTIONARY, duplicate_result->GetType()); 594 EXPECT_EQ(base::Value::TYPE_DICTIONARY, duplicate_result->GetType());
593 // Duplicate tab id should be different from the original tab id. 595 // Duplicate tab id should be different from the original tab id.
594 EXPECT_NE(tab_id, duplicate_tab_id); 596 EXPECT_NE(tab_id, duplicate_tab_id);
595 EXPECT_EQ(window_id, duplicate_tab_window_id); 597 EXPECT_EQ(window_id, duplicate_tab_window_id);
596 EXPECT_EQ(tab_index + 1, duplicate_tab_index); 598 EXPECT_EQ(tab_index + 1, duplicate_tab_index);
597 // The test empty extension has no permissions, therefore |duplicate_result| 599 // The test empty extension has no permissions, therefore |duplicate_result|
598 // should not contain url, title, and faviconUrl in the function result. 600 // should not contain url, title, and faviconUrl in the function result.
599 EXPECT_FALSE(utils::HasPrivacySensitiveFields(duplicate_result.get())); 601 EXPECT_FALSE(utils::HasPrivacySensitiveFields(duplicate_result.get()));
600 } 602 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698