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

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

Issue 11826048: Revert 176015 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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"
5 6
6 #include <string> 7 #include <string>
7 8
8 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/stringprintf.h"
10 #include "base/string_util.h" 12 #include "base/string_util.h"
11 #include "base/stringprintf.h"
12 #include "base/values.h" 13 #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<WindowsGetFunction> function = new WindowsGetFunction(); 41 scoped_refptr<GetWindowFunction> function = new GetWindowFunction();
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 WindowsGetFunction(); 58 function = new GetWindowFunction();
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 WindowsGetFunction(); 74 function = new GetWindowFunction();
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 WindowsGetFunction(); 99 function = new GetWindowFunction();
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 WindowsGetFunction(); 112 function = new GetWindowFunction();
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 WindowsGetFunction(); 127 function = new GetWindowFunction();
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 WindowsGetFunction(); 137 function = new GetWindowFunction();
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<WindowsGetCurrentFunction> function = 154 scoped_refptr<GetCurrentWindowFunction> function =
155 new WindowsGetCurrentFunction(); 155 new GetCurrentWindowFunction();
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 WindowsGetCurrentFunction(); 170 function = new GetCurrentWindowFunction();
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<WindowsGetAllFunction> function = new WindowsGetAllFunction(); 195 scoped_refptr<GetAllWindowsFunction> function = new GetAllWindowsFunction();
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 WindowsGetAllFunction(); 218 function = new GetAllWindowsFunction();
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<TabsUpdateFunction> update_tab_function( 243 scoped_refptr<UpdateTabFunction> update_tab_function(new UpdateTabFunction());
244 new TabsUpdateFunction());
245 scoped_refptr<extensions::Extension> empty_extension( 244 scoped_refptr<extensions::Extension> empty_extension(
246 utils::CreateEmptyExtension()); 245 utils::CreateEmptyExtension());
247 update_tab_function->set_extension(empty_extension.get()); 246 update_tab_function->set_extension(empty_extension.get());
248 // Without a callback the function will not generate a result. 247 // Without a callback the function will not generate a result.
249 update_tab_function->set_has_callback(true); 248 update_tab_function->set_has_callback(true);
250 249
251 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( 250 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary(
252 utils::RunFunctionAndReturnSingleResult( 251 utils::RunFunctionAndReturnSingleResult(
253 update_tab_function.get(), 252 update_tab_function.get(),
254 "[null, {\"url\": \"about:blank\", \"pinned\": true}]", 253 "[null, {\"url\": \"about:blank\", \"pinned\": true}]",
255 browser()))); 254 browser())));
256 // The url is stripped since the extension does not have tab permissions. 255 // The url is stripped since the extension does not have tab permissions.
257 EXPECT_FALSE(result->HasKey("url")); 256 EXPECT_FALSE(result->HasKey("url"));
258 EXPECT_TRUE(utils::GetBoolean(result.get(), "pinned")); 257 EXPECT_TRUE(utils::GetBoolean(result.get(), "pinned"));
259 } 258 }
260 259
261 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, 260 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest,
262 DefaultToIncognitoWhenItIsForced) { 261 DefaultToIncognitoWhenItIsForced) {
263 static const char kArgsWithoutExplicitIncognitoParam[] = 262 static const char kArgsWithoutExplicitIncognitoParam[] =
264 "[{\"url\": \"about:blank\"}]"; 263 "[{\"url\": \"about:blank\"}]";
265 // Force Incognito mode. 264 // Force Incognito mode.
266 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), 265 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(),
267 IncognitoModePrefs::FORCED); 266 IncognitoModePrefs::FORCED);
268 // Run without an explicit "incognito" param. 267 // Run without an explicit "incognito" param.
269 scoped_refptr<WindowsCreateFunction> function(new WindowsCreateFunction()); 268 scoped_refptr<CreateWindowFunction> function(new CreateWindowFunction());
270 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension()); 269 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension());
271 function->set_extension(extension.get()); 270 function->set_extension(extension.get());
272 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( 271 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary(
273 utils::RunFunctionAndReturnSingleResult( 272 utils::RunFunctionAndReturnSingleResult(
274 function.get(), 273 function.get(),
275 kArgsWithoutExplicitIncognitoParam, 274 kArgsWithoutExplicitIncognitoParam,
276 browser(), 275 browser(),
277 utils::INCLUDE_INCOGNITO))); 276 utils::INCLUDE_INCOGNITO)));
278 277
279 // Make sure it is a new(different) window. 278 // Make sure it is a new(different) window.
280 EXPECT_NE(ExtensionTabUtil::GetWindowId(browser()), 279 EXPECT_NE(ExtensionTabUtil::GetWindowId(browser()),
281 utils::GetInteger(result.get(), "id")); 280 utils::GetInteger(result.get(), "id"));
282 // ... and it is incognito. 281 // ... and it is incognito.
283 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito")); 282 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito"));
284 283
285 // Now try creating a window from incognito window. 284 // Now try creating a window from incognito window.
286 Browser* incognito_browser = CreateIncognitoBrowser(); 285 Browser* incognito_browser = CreateIncognitoBrowser();
287 // Run without an explicit "incognito" param. 286 // Run without an explicit "incognito" param.
288 function = new WindowsCreateFunction(); 287 function = new CreateWindowFunction();
289 function->set_extension(extension.get()); 288 function->set_extension(extension.get());
290 result.reset(utils::ToDictionary( 289 result.reset(utils::ToDictionary(
291 utils::RunFunctionAndReturnSingleResult( 290 utils::RunFunctionAndReturnSingleResult(
292 function.get(), 291 function.get(),
293 kArgsWithoutExplicitIncognitoParam, 292 kArgsWithoutExplicitIncognitoParam,
294 incognito_browser, 293 incognito_browser,
295 utils::INCLUDE_INCOGNITO))); 294 utils::INCLUDE_INCOGNITO)));
296 // Make sure it is a new(different) window. 295 // Make sure it is a new(different) window.
297 EXPECT_NE(ExtensionTabUtil::GetWindowId(incognito_browser), 296 EXPECT_NE(ExtensionTabUtil::GetWindowId(incognito_browser),
298 utils::GetInteger(result.get(), "id")); 297 utils::GetInteger(result.get(), "id"));
299 // ... and it is incognito. 298 // ... and it is incognito.
300 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito")); 299 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito"));
301 } 300 }
302 301
303 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, 302 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest,
304 DefaultToIncognitoWhenItIsForcedAndNoArgs) { 303 DefaultToIncognitoWhenItIsForcedAndNoArgs) {
305 static const char kEmptyArgs[] = "[]"; 304 static const char kEmptyArgs[] = "[]";
306 // Force Incognito mode. 305 // Force Incognito mode.
307 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), 306 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(),
308 IncognitoModePrefs::FORCED); 307 IncognitoModePrefs::FORCED);
309 // Run without an explicit "incognito" param. 308 // Run without an explicit "incognito" param.
310 scoped_refptr<WindowsCreateFunction> function = new WindowsCreateFunction(); 309 scoped_refptr<CreateWindowFunction> function = new CreateWindowFunction();
311 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension()); 310 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension());
312 function->set_extension(extension.get()); 311 function->set_extension(extension.get());
313 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( 312 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary(
314 utils::RunFunctionAndReturnSingleResult(function.get(), 313 utils::RunFunctionAndReturnSingleResult(function.get(),
315 kEmptyArgs, 314 kEmptyArgs,
316 browser(), 315 browser(),
317 utils::INCLUDE_INCOGNITO))); 316 utils::INCLUDE_INCOGNITO)));
318 317
319 // Make sure it is a new(different) window. 318 // Make sure it is a new(different) window.
320 EXPECT_NE(ExtensionTabUtil::GetWindowId(browser()), 319 EXPECT_NE(ExtensionTabUtil::GetWindowId(browser()),
321 utils::GetInteger(result.get(), "id")); 320 utils::GetInteger(result.get(), "id"));
322 // ... and it is incognito. 321 // ... and it is incognito.
323 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito")); 322 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito"));
324 323
325 // Now try creating a window from incognito window. 324 // Now try creating a window from incognito window.
326 Browser* incognito_browser = CreateIncognitoBrowser(); 325 Browser* incognito_browser = CreateIncognitoBrowser();
327 // Run without an explicit "incognito" param. 326 // Run without an explicit "incognito" param.
328 function = new WindowsCreateFunction(); 327 function = new CreateWindowFunction();
329 function->set_extension(extension.get()); 328 function->set_extension(extension.get());
330 result.reset(utils::ToDictionary( 329 result.reset(utils::ToDictionary(
331 utils::RunFunctionAndReturnSingleResult(function.get(), 330 utils::RunFunctionAndReturnSingleResult(function.get(),
332 kEmptyArgs, 331 kEmptyArgs,
333 incognito_browser, 332 incognito_browser,
334 utils::INCLUDE_INCOGNITO))); 333 utils::INCLUDE_INCOGNITO)));
335 // Make sure it is a new(different) window. 334 // Make sure it is a new(different) window.
336 EXPECT_NE(ExtensionTabUtil::GetWindowId(incognito_browser), 335 EXPECT_NE(ExtensionTabUtil::GetWindowId(incognito_browser),
337 utils::GetInteger(result.get(), "id")); 336 utils::GetInteger(result.get(), "id"));
338 // ... and it is incognito. 337 // ... and it is incognito.
339 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito")); 338 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito"));
340 } 339 }
341 340
342 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, 341 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest,
343 DontCreateNormalWindowWhenIncognitoForced) { 342 DontCreateNormalWindowWhenIncognitoForced) {
344 static const char kArgsWithExplicitIncognitoParam[] = 343 static const char kArgsWithExplicitIncognitoParam[] =
345 "[{\"url\": \"about:blank\", \"incognito\": false }]"; 344 "[{\"url\": \"about:blank\", \"incognito\": false }]";
346 // Force Incognito mode. 345 // Force Incognito mode.
347 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), 346 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(),
348 IncognitoModePrefs::FORCED); 347 IncognitoModePrefs::FORCED);
349 348
350 // Run with an explicit "incognito" param. 349 // Run with an explicit "incognito" param.
351 scoped_refptr<WindowsCreateFunction> function = new WindowsCreateFunction(); 350 scoped_refptr<CreateWindowFunction> function = new CreateWindowFunction();
352 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension()); 351 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension());
353 function->set_extension(extension.get()); 352 function->set_extension(extension.get());
354 EXPECT_TRUE(MatchPattern( 353 EXPECT_TRUE(MatchPattern(
355 utils::RunFunctionAndReturnError(function.get(), 354 utils::RunFunctionAndReturnError(function.get(),
356 kArgsWithExplicitIncognitoParam, 355 kArgsWithExplicitIncognitoParam,
357 browser()), 356 browser()),
358 keys::kIncognitoModeIsForced)); 357 keys::kIncognitoModeIsForced));
359 358
360 // Now try opening a normal window from incognito window. 359 // Now try opening a normal window from incognito window.
361 Browser* incognito_browser = CreateIncognitoBrowser(); 360 Browser* incognito_browser = CreateIncognitoBrowser();
362 // Run with an explicit "incognito" param. 361 // Run with an explicit "incognito" param.
363 function = new WindowsCreateFunction(); 362 function = new CreateWindowFunction();
364 function->set_extension(extension.get()); 363 function->set_extension(extension.get());
365 EXPECT_TRUE(MatchPattern( 364 EXPECT_TRUE(MatchPattern(
366 utils::RunFunctionAndReturnError(function.get(), 365 utils::RunFunctionAndReturnError(function.get(),
367 kArgsWithExplicitIncognitoParam, 366 kArgsWithExplicitIncognitoParam,
368 incognito_browser), 367 incognito_browser),
369 keys::kIncognitoModeIsForced)); 368 keys::kIncognitoModeIsForced));
370 } 369 }
371 370
372 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, 371 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest,
373 DontCreateIncognitoWindowWhenIncognitoDisabled) { 372 DontCreateIncognitoWindowWhenIncognitoDisabled) {
374 static const char kArgs[] = 373 static const char kArgs[] =
375 "[{\"url\": \"about:blank\", \"incognito\": true }]"; 374 "[{\"url\": \"about:blank\", \"incognito\": true }]";
376 375
377 Browser* incognito_browser = CreateIncognitoBrowser(); 376 Browser* incognito_browser = CreateIncognitoBrowser();
378 // Disable Incognito mode. 377 // Disable Incognito mode.
379 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), 378 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(),
380 IncognitoModePrefs::DISABLED); 379 IncognitoModePrefs::DISABLED);
381 // Run in normal window. 380 // Run in normal window.
382 scoped_refptr<WindowsCreateFunction> function = new WindowsCreateFunction(); 381 scoped_refptr<CreateWindowFunction> function = new CreateWindowFunction();
383 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension()); 382 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension());
384 function->set_extension(extension.get()); 383 function->set_extension(extension.get());
385 EXPECT_TRUE(MatchPattern( 384 EXPECT_TRUE(MatchPattern(
386 utils::RunFunctionAndReturnError(function.get(), 385 utils::RunFunctionAndReturnError(function.get(),
387 kArgs, 386 kArgs,
388 browser()), 387 browser()),
389 keys::kIncognitoModeIsDisabled)); 388 keys::kIncognitoModeIsDisabled));
390 389
391 // Run in incognito window. 390 // Run in incognito window.
392 function = new WindowsCreateFunction(); 391 function = new CreateWindowFunction();
393 function->set_extension(extension.get()); 392 function->set_extension(extension.get());
394 EXPECT_TRUE(MatchPattern( 393 EXPECT_TRUE(MatchPattern(
395 utils::RunFunctionAndReturnError(function.get(), 394 utils::RunFunctionAndReturnError(function.get(),
396 kArgs, 395 kArgs,
397 incognito_browser), 396 incognito_browser),
398 keys::kIncognitoModeIsDisabled)); 397 keys::kIncognitoModeIsDisabled));
399 } 398 }
400 399
401 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, QueryCurrentWindowTabs) { 400 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, QueryCurrentWindowTabs) {
402 const size_t kExtraWindows = 3; 401 const size_t kExtraWindows = 3;
403 for (size_t i = 0; i < kExtraWindows; ++i) 402 for (size_t i = 0; i < kExtraWindows; ++i)
404 CreateBrowser(browser()->profile()); 403 CreateBrowser(browser()->profile());
405 404
406 GURL url; 405 GURL url;
407 AddTabAtIndexToBrowser(browser(), 0, url, content::PAGE_TRANSITION_LINK); 406 AddTabAtIndexToBrowser(browser(), 0, url, content::PAGE_TRANSITION_LINK);
408 int window_id = ExtensionTabUtil::GetWindowId(browser()); 407 int window_id = ExtensionTabUtil::GetWindowId(browser());
409 408
410 // Get tabs in the 'current' window called from non-focused browser. 409 // Get tabs in the 'current' window called from non-focused browser.
411 scoped_refptr<TabsQueryFunction> function = new TabsQueryFunction(); 410 scoped_refptr<QueryTabsFunction> function = new QueryTabsFunction();
412 function->set_extension(utils::CreateEmptyExtension().get()); 411 function->set_extension(utils::CreateEmptyExtension().get());
413 scoped_ptr<base::ListValue> result(utils::ToList( 412 scoped_ptr<base::ListValue> result(utils::ToList(
414 utils::RunFunctionAndReturnSingleResult(function.get(), 413 utils::RunFunctionAndReturnSingleResult(function.get(),
415 "[{\"currentWindow\":true}]", 414 "[{\"currentWindow\":true}]",
416 browser()))); 415 browser())));
417 416
418 ListValue* result_tabs = result.get(); 417 ListValue* result_tabs = result.get();
419 // We should have one initial tab and one added tab. 418 // We should have one initial tab and one added tab.
420 EXPECT_EQ(2u, result_tabs->GetSize()); 419 EXPECT_EQ(2u, result_tabs->GetSize());
421 for (size_t i = 0; i < result_tabs->GetSize(); ++i) { 420 for (size_t i = 0; i < result_tabs->GetSize(); ++i) {
422 DictionaryValue* result_tab = NULL; 421 DictionaryValue* result_tab = NULL;
423 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); 422 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab));
424 EXPECT_EQ(window_id, utils::GetInteger(result_tab, keys::kWindowIdKey)); 423 EXPECT_EQ(window_id, utils::GetInteger(result_tab, keys::kWindowIdKey));
425 } 424 }
426 425
427 // Get tabs NOT in the 'current' window called from non-focused browser. 426 // Get tabs NOT in the 'current' window called from non-focused browser.
428 function = new TabsQueryFunction(); 427 function = new QueryTabsFunction();
429 function->set_extension(utils::CreateEmptyExtension().get()); 428 function->set_extension(utils::CreateEmptyExtension().get());
430 result.reset(utils::ToList( 429 result.reset(utils::ToList(
431 utils::RunFunctionAndReturnSingleResult(function.get(), 430 utils::RunFunctionAndReturnSingleResult(function.get(),
432 "[{\"currentWindow\":false}]", 431 "[{\"currentWindow\":false}]",
433 browser()))); 432 browser())));
434 433
435 result_tabs = result.get(); 434 result_tabs = result.get();
436 // We should have one tab for each extra window. 435 // We should have one tab for each extra window.
437 EXPECT_EQ(kExtraWindows, result_tabs->GetSize()); 436 EXPECT_EQ(kExtraWindows, result_tabs->GetSize());
438 for (size_t i = 0; i < kExtraWindows; ++i) { 437 for (size_t i = 0; i < kExtraWindows; ++i) {
439 DictionaryValue* result_tab = NULL; 438 DictionaryValue* result_tab = NULL;
440 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); 439 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab));
441 EXPECT_NE(window_id, utils::GetInteger(result_tab, keys::kWindowIdKey)); 440 EXPECT_NE(window_id, utils::GetInteger(result_tab, keys::kWindowIdKey));
442 } 441 }
443 } 442 }
444 443
445 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DontCreateTabInClosingPopupWindow) { 444 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DontCreateTabInClosingPopupWindow) {
446 // Test creates new popup window, closes it right away and then tries to open 445 // Test creates new popup window, closes it right away and then tries to open
447 // a new tab in it. Tab should not be opened in the popup window, but in a 446 // a new tab in it. Tab should not be opened in the popup window, but in a
448 // tabbed browser window. 447 // tabbed browser window.
449 Browser* popup_browser = new Browser( 448 Browser* popup_browser = new Browser(
450 Browser::CreateParams(Browser::TYPE_POPUP, browser()->profile())); 449 Browser::CreateParams(Browser::TYPE_POPUP, browser()->profile()));
451 int window_id = ExtensionTabUtil::GetWindowId(popup_browser); 450 int window_id = ExtensionTabUtil::GetWindowId(popup_browser);
452 chrome::CloseWindow(popup_browser); 451 chrome::CloseWindow(popup_browser);
453 452
454 scoped_refptr<TabsCreateFunction> create_tab_function( 453 scoped_refptr<CreateTabFunction> create_tab_function(new CreateTabFunction());
455 new TabsCreateFunction());
456 create_tab_function->set_extension(utils::CreateEmptyExtension().get()); 454 create_tab_function->set_extension(utils::CreateEmptyExtension().get());
457 // Without a callback the function will not generate a result. 455 // Without a callback the function will not generate a result.
458 create_tab_function->set_has_callback(true); 456 create_tab_function->set_has_callback(true);
459 457
460 static const char kNewBlankTabArgs[] = 458 static const char kNewBlankTabArgs[] =
461 "[{\"url\": \"about:blank\", \"windowId\": %u}]"; 459 "[{\"url\": \"about:blank\", \"windowId\": %u}]";
462 460
463 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( 461 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary(
464 utils::RunFunctionAndReturnSingleResult( 462 utils::RunFunctionAndReturnSingleResult(
465 create_tab_function.get(), 463 create_tab_function.get(),
466 base::StringPrintf(kNewBlankTabArgs, window_id), 464 base::StringPrintf(kNewBlankTabArgs, window_id),
467 browser()))); 465 browser())));
468 466
469 EXPECT_NE(window_id, utils::GetInteger(result.get(), "windowId")); 467 EXPECT_NE(window_id, utils::GetInteger(result.get(), "windowId"));
470 } 468 }
471 469
472 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, InvalidUpdateWindowState) { 470 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, InvalidUpdateWindowState) {
473 int window_id = ExtensionTabUtil::GetWindowId(browser()); 471 int window_id = ExtensionTabUtil::GetWindowId(browser());
474 472
475 static const char kArgsMinimizedWithFocus[] = 473 static const char kArgsMinimizedWithFocus[] =
476 "[%u, {\"state\": \"minimized\", \"focused\": true}]"; 474 "[%u, {\"state\": \"minimized\", \"focused\": true}]";
477 scoped_refptr<WindowsUpdateFunction> function = new WindowsUpdateFunction(); 475 scoped_refptr<UpdateWindowFunction> function = new UpdateWindowFunction();
478 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension()); 476 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension());
479 function->set_extension(extension.get()); 477 function->set_extension(extension.get());
480 EXPECT_TRUE(MatchPattern( 478 EXPECT_TRUE(MatchPattern(
481 utils::RunFunctionAndReturnError( 479 utils::RunFunctionAndReturnError(
482 function.get(), 480 function.get(),
483 base::StringPrintf(kArgsMinimizedWithFocus, window_id), 481 base::StringPrintf(kArgsMinimizedWithFocus, window_id),
484 browser()), 482 browser()),
485 keys::kInvalidWindowStateError)); 483 keys::kInvalidWindowStateError));
486 484
487 static const char kArgsMaximizedWithoutFocus[] = 485 static const char kArgsMaximizedWithoutFocus[] =
488 "[%u, {\"state\": \"maximized\", \"focused\": false}]"; 486 "[%u, {\"state\": \"maximized\", \"focused\": false}]";
489 function = new WindowsUpdateFunction(); 487 function = new UpdateWindowFunction();
490 function->set_extension(extension.get()); 488 function->set_extension(extension.get());
491 EXPECT_TRUE(MatchPattern( 489 EXPECT_TRUE(MatchPattern(
492 utils::RunFunctionAndReturnError( 490 utils::RunFunctionAndReturnError(
493 function.get(), 491 function.get(),
494 base::StringPrintf(kArgsMaximizedWithoutFocus, window_id), 492 base::StringPrintf(kArgsMaximizedWithoutFocus, window_id),
495 browser()), 493 browser()),
496 keys::kInvalidWindowStateError)); 494 keys::kInvalidWindowStateError));
497 495
498 static const char kArgsMinimizedWithBounds[] = 496 static const char kArgsMinimizedWithBounds[] =
499 "[%u, {\"state\": \"minimized\", \"width\": 500}]"; 497 "[%u, {\"state\": \"minimized\", \"width\": 500}]";
500 function = new WindowsUpdateFunction(); 498 function = new UpdateWindowFunction();
501 function->set_extension(extension.get()); 499 function->set_extension(extension.get());
502 EXPECT_TRUE(MatchPattern( 500 EXPECT_TRUE(MatchPattern(
503 utils::RunFunctionAndReturnError( 501 utils::RunFunctionAndReturnError(
504 function.get(), 502 function.get(),
505 base::StringPrintf(kArgsMinimizedWithBounds, window_id), 503 base::StringPrintf(kArgsMinimizedWithBounds, window_id),
506 browser()), 504 browser()),
507 keys::kInvalidWindowStateError)); 505 keys::kInvalidWindowStateError));
508 506
509 static const char kArgsMaximizedWithBounds[] = 507 static const char kArgsMaximizedWithBounds[] =
510 "[%u, {\"state\": \"maximized\", \"width\": 500}]"; 508 "[%u, {\"state\": \"maximized\", \"width\": 500}]";
511 function = new WindowsUpdateFunction(); 509 function = new UpdateWindowFunction();
512 function->set_extension(extension.get()); 510 function->set_extension(extension.get());
513 EXPECT_TRUE(MatchPattern( 511 EXPECT_TRUE(MatchPattern(
514 utils::RunFunctionAndReturnError( 512 utils::RunFunctionAndReturnError(
515 function.get(), 513 function.get(),
516 base::StringPrintf(kArgsMaximizedWithBounds, window_id), 514 base::StringPrintf(kArgsMaximizedWithBounds, window_id),
517 browser()), 515 browser()),
518 keys::kInvalidWindowStateError)); 516 keys::kInvalidWindowStateError));
519 } 517 }
520 518
521 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DuplicateTab) { 519 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DuplicateTab) {
522 static const char kNewBlankTabArgs[] ="about:blank"; 520 static const char kNewBlankTabArgs[] ="about:blank";
523 521
524 content::OpenURLParams params(GURL(kNewBlankTabArgs), content::Referrer(), 522 content::OpenURLParams params(GURL(kNewBlankTabArgs), content::Referrer(),
525 NEW_FOREGROUND_TAB, 523 NEW_FOREGROUND_TAB,
526 content::PAGE_TRANSITION_LINK, false); 524 content::PAGE_TRANSITION_LINK, false);
527 content::WebContents* web_contents = browser()->OpenURL(params); 525 content::WebContents* web_contents = browser()->OpenURL(params);
528 int tab_id = ExtensionTabUtil::GetTabId(web_contents); 526 int tab_id = ExtensionTabUtil::GetTabId(web_contents);
529 int window_id = ExtensionTabUtil::GetWindowIdOfTab(web_contents); 527 int window_id = ExtensionTabUtil::GetWindowIdOfTab(web_contents);
530 int tab_index = -1; 528 int tab_index = -1;
531 TabStripModel* tab_strip; 529 TabStripModel* tab_strip;
532 ExtensionTabUtil::GetTabStripModel(web_contents, &tab_strip, &tab_index); 530 ExtensionTabUtil::GetTabStripModel(web_contents, &tab_strip, &tab_index);
533 531
534 scoped_refptr<TabsDuplicateFunction> duplicate_tab_function( 532 scoped_refptr<DuplicateTabFunction> duplicate_tab_function(
535 new TabsDuplicateFunction()); 533 new DuplicateTabFunction());
536 scoped_ptr<base::DictionaryValue> test_extension_value( 534 scoped_ptr<base::DictionaryValue> test_extension_value(
537 utils::ParseDictionary( 535 utils::ParseDictionary(
538 "{\"name\": \"Test\", \"version\": \"1.0\", \"permissions\": [\"tabs\"]}" 536 "{\"name\": \"Test\", \"version\": \"1.0\", \"permissions\": [\"tabs\"]}"
539 )); 537 ));
540 scoped_refptr<extensions::Extension> empty_tab_extension( 538 scoped_refptr<extensions::Extension> empty_tab_extension(
541 utils::CreateExtension(test_extension_value.get())); 539 utils::CreateExtension(test_extension_value.get()));
542 duplicate_tab_function->set_extension(empty_tab_extension.get()); 540 duplicate_tab_function->set_extension(empty_tab_extension.get());
543 duplicate_tab_function->set_has_callback(true); 541 duplicate_tab_function->set_has_callback(true);
544 542
545 scoped_ptr<base::DictionaryValue> duplicate_result(utils::ToDictionary( 543 scoped_ptr<base::DictionaryValue> duplicate_result(utils::ToDictionary(
(...skipping 22 matching lines...) Expand all
568 content::OpenURLParams params(GURL(kNewBlankTabArgs), content::Referrer(), 566 content::OpenURLParams params(GURL(kNewBlankTabArgs), content::Referrer(),
569 NEW_FOREGROUND_TAB, 567 NEW_FOREGROUND_TAB,
570 content::PAGE_TRANSITION_LINK, false); 568 content::PAGE_TRANSITION_LINK, false);
571 content::WebContents* web_contents = browser()->OpenURL(params); 569 content::WebContents* web_contents = browser()->OpenURL(params);
572 int tab_id = ExtensionTabUtil::GetTabId(web_contents); 570 int tab_id = ExtensionTabUtil::GetTabId(web_contents);
573 int window_id = ExtensionTabUtil::GetWindowIdOfTab(web_contents); 571 int window_id = ExtensionTabUtil::GetWindowIdOfTab(web_contents);
574 int tab_index = -1; 572 int tab_index = -1;
575 TabStripModel* tab_strip; 573 TabStripModel* tab_strip;
576 ExtensionTabUtil::GetTabStripModel(web_contents, &tab_strip, &tab_index); 574 ExtensionTabUtil::GetTabStripModel(web_contents, &tab_strip, &tab_index);
577 575
578 scoped_refptr<TabsDuplicateFunction> duplicate_tab_function( 576 scoped_refptr<DuplicateTabFunction> duplicate_tab_function(
579 new TabsDuplicateFunction()); 577 new DuplicateTabFunction());
580 scoped_refptr<extensions::Extension> empty_extension( 578 scoped_refptr<extensions::Extension> empty_extension(
581 utils::CreateEmptyExtension()); 579 utils::CreateEmptyExtension());
582 duplicate_tab_function->set_extension(empty_extension.get()); 580 duplicate_tab_function->set_extension(empty_extension.get());
583 duplicate_tab_function->set_has_callback(true); 581 duplicate_tab_function->set_has_callback(true);
584 582
585 scoped_ptr<base::DictionaryValue> duplicate_result(utils::ToDictionary( 583 scoped_ptr<base::DictionaryValue> duplicate_result(utils::ToDictionary(
586 utils::RunFunctionAndReturnSingleResult( 584 utils::RunFunctionAndReturnSingleResult(
587 duplicate_tab_function.get(), base::StringPrintf("[%u]", tab_id), 585 duplicate_tab_function.get(), base::StringPrintf("[%u]", tab_id),
588 browser()))); 586 browser())));
589 587
590 int duplicate_tab_id = utils::GetInteger(duplicate_result.get(), "id"); 588 int duplicate_tab_id = utils::GetInteger(duplicate_result.get(), "id");
591 int duplicate_tab_window_id = utils::GetInteger(duplicate_result.get(), 589 int duplicate_tab_window_id = utils::GetInteger(duplicate_result.get(),
592 "windowId"); 590 "windowId");
593 int duplicate_tab_index = utils::GetInteger(duplicate_result.get(), "index"); 591 int duplicate_tab_index = utils::GetInteger(duplicate_result.get(), "index");
594 EXPECT_EQ(base::Value::TYPE_DICTIONARY, duplicate_result->GetType()); 592 EXPECT_EQ(base::Value::TYPE_DICTIONARY, duplicate_result->GetType());
595 // Duplicate tab id should be different from the original tab id. 593 // Duplicate tab id should be different from the original tab id.
596 EXPECT_NE(tab_id, duplicate_tab_id); 594 EXPECT_NE(tab_id, duplicate_tab_id);
597 EXPECT_EQ(window_id, duplicate_tab_window_id); 595 EXPECT_EQ(window_id, duplicate_tab_window_id);
598 EXPECT_EQ(tab_index + 1, duplicate_tab_index); 596 EXPECT_EQ(tab_index + 1, duplicate_tab_index);
599 // The test empty extension has no permissions, therefore |duplicate_result| 597 // The test empty extension has no permissions, therefore |duplicate_result|
600 // should not contain url, title, and faviconUrl in the function result. 598 // should not contain url, title, and faviconUrl in the function result.
601 EXPECT_FALSE(utils::HasPrivacySensitiveFields(duplicate_result.get())); 599 EXPECT_FALSE(utils::HasPrivacySensitiveFields(duplicate_result.get()));
602 } 600 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698