| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/api/tabs/tabs.h" | 5 #include "chrome/browser/extensions/api/tabs/tabs.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 class ExtensionTabsTest : public InProcessBrowserTest { | 31 class ExtensionTabsTest : public InProcessBrowserTest { |
| 32 }; | 32 }; |
| 33 } | 33 } |
| 34 | 34 |
| 35 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetWindow) { | 35 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetWindow) { |
| 36 int window_id = ExtensionTabUtil::GetWindowId(browser()); | 36 int window_id = ExtensionTabUtil::GetWindowId(browser()); |
| 37 | 37 |
| 38 // Invalid window ID error. | 38 // Invalid window ID error. |
| 39 scoped_refptr<GetWindowFunction> function = new GetWindowFunction(); | 39 scoped_refptr<GetWindowFunction> function = new GetWindowFunction(); |
| 40 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension()); |
| 41 function->set_extension(extension.get()); |
| 40 EXPECT_TRUE(MatchPattern( | 42 EXPECT_TRUE(MatchPattern( |
| 41 utils::RunFunctionAndReturnError( | 43 utils::RunFunctionAndReturnError( |
| 42 function.get(), | 44 function.get(), |
| 43 base::StringPrintf("[%u]", window_id + 1), | 45 base::StringPrintf("[%u]", window_id + 1), |
| 44 browser()), | 46 browser()), |
| 45 keys::kWindowNotFoundError)); | 47 keys::kWindowNotFoundError)); |
| 46 | 48 |
| 47 // Basic window details. | 49 // Basic window details. |
| 48 gfx::Rect bounds; | 50 gfx::Rect bounds; |
| 49 if (browser()->window()->IsMinimized()) | 51 if (browser()->window()->IsMinimized()) |
| 50 bounds = browser()->window()->GetRestoredBounds(); | 52 bounds = browser()->window()->GetRestoredBounds(); |
| 51 else | 53 else |
| 52 bounds = browser()->window()->GetBounds(); | 54 bounds = browser()->window()->GetBounds(); |
| 53 | 55 |
| 54 function = new GetWindowFunction(); | 56 function = new GetWindowFunction(); |
| 57 function->set_extension(extension.get()); |
| 55 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( | 58 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( |
| 56 utils::RunFunctionAndReturnSingleResult( | 59 utils::RunFunctionAndReturnSingleResult( |
| 57 function.get(), | 60 function.get(), |
| 58 base::StringPrintf("[%u]", window_id), | 61 base::StringPrintf("[%u]", window_id), |
| 59 browser()))); | 62 browser()))); |
| 60 EXPECT_EQ(window_id, utils::GetInteger(result.get(), "id")); | 63 EXPECT_EQ(window_id, utils::GetInteger(result.get(), "id")); |
| 61 EXPECT_FALSE(utils::GetBoolean(result.get(), "incognito")); | 64 EXPECT_FALSE(utils::GetBoolean(result.get(), "incognito")); |
| 62 EXPECT_EQ("normal", utils::GetString(result.get(), "type")); | 65 EXPECT_EQ("normal", utils::GetString(result.get(), "type")); |
| 63 EXPECT_EQ(bounds.x(), utils::GetInteger(result.get(), "left")); | 66 EXPECT_EQ(bounds.x(), utils::GetInteger(result.get(), "left")); |
| 64 EXPECT_EQ(bounds.y(), utils::GetInteger(result.get(), "top")); | 67 EXPECT_EQ(bounds.y(), utils::GetInteger(result.get(), "top")); |
| 65 EXPECT_EQ(bounds.width(), utils::GetInteger(result.get(), "width")); | 68 EXPECT_EQ(bounds.width(), utils::GetInteger(result.get(), "width")); |
| 66 EXPECT_EQ(bounds.height(), utils::GetInteger(result.get(), "height")); | 69 EXPECT_EQ(bounds.height(), utils::GetInteger(result.get(), "height")); |
| 67 | 70 |
| 68 // With "populate" enabled. | 71 // With "populate" enabled. |
| 69 function = new GetWindowFunction(); | 72 function = new GetWindowFunction(); |
| 73 function->set_extension(extension.get()); |
| 70 result.reset(utils::ToDictionary( | 74 result.reset(utils::ToDictionary( |
| 71 utils::RunFunctionAndReturnSingleResult( | 75 utils::RunFunctionAndReturnSingleResult( |
| 72 function.get(), | 76 function.get(), |
| 73 base::StringPrintf("[%u, {\"populate\": true}]", window_id), | 77 base::StringPrintf("[%u, {\"populate\": true}]", window_id), |
| 74 browser()))); | 78 browser()))); |
| 75 | 79 |
| 76 EXPECT_EQ(window_id, utils::GetInteger(result.get(), "id")); | 80 EXPECT_EQ(window_id, utils::GetInteger(result.get(), "id")); |
| 77 // "populate" was enabled so tabs should be populated. | 81 // "populate" was enabled so tabs should be populated. |
| 78 ListValue* tabs = NULL; | 82 ListValue* tabs = NULL; |
| 79 EXPECT_TRUE(result.get()->GetList(keys::kTabsKey, &tabs)); | 83 EXPECT_TRUE(result.get()->GetList(keys::kTabsKey, &tabs)); |
| 80 | 84 |
| 81 // TODO(aa): Can't assume window is focused. On mac, calling Activate() from a | 85 // TODO(aa): Can't assume window is focused. On mac, calling Activate() from a |
| 82 // browser test doesn't seem to do anything, so can't test the opposite | 86 // browser test doesn't seem to do anything, so can't test the opposite |
| 83 // either. | 87 // either. |
| 84 EXPECT_EQ(browser()->window()->IsActive(), | 88 EXPECT_EQ(browser()->window()->IsActive(), |
| 85 utils::GetBoolean(result.get(), "focused")); | 89 utils::GetBoolean(result.get(), "focused")); |
| 86 | 90 |
| 87 // TODO(aa): Minimized and maximized dimensions. Is there a way to set | 91 // TODO(aa): Minimized and maximized dimensions. Is there a way to set |
| 88 // minimize/maximize programmatically? | 92 // minimize/maximize programmatically? |
| 89 | 93 |
| 90 // Popup. | 94 // Popup. |
| 91 Browser* popup_browser = new Browser( | 95 Browser* popup_browser = new Browser( |
| 92 Browser::CreateParams(Browser::TYPE_POPUP, browser()->profile())); | 96 Browser::CreateParams(Browser::TYPE_POPUP, browser()->profile())); |
| 93 function = new GetWindowFunction(); | 97 function = new GetWindowFunction(); |
| 98 function->set_extension(extension.get()); |
| 94 result.reset(utils::ToDictionary( | 99 result.reset(utils::ToDictionary( |
| 95 utils::RunFunctionAndReturnSingleResult( | 100 utils::RunFunctionAndReturnSingleResult( |
| 96 function.get(), | 101 function.get(), |
| 97 base::StringPrintf( | 102 base::StringPrintf( |
| 98 "[%u]", ExtensionTabUtil::GetWindowId(popup_browser)), | 103 "[%u]", ExtensionTabUtil::GetWindowId(popup_browser)), |
| 99 browser()))); | 104 browser()))); |
| 100 EXPECT_EQ("popup", utils::GetString(result.get(), "type")); | 105 EXPECT_EQ("popup", utils::GetString(result.get(), "type")); |
| 101 | 106 |
| 102 // Panel. | 107 // Panel. |
| 103 Browser* panel_browser = new Browser( | 108 Browser* panel_browser = new Browser( |
| 104 Browser::CreateParams(Browser::TYPE_PANEL, browser()->profile())); | 109 Browser::CreateParams(Browser::TYPE_PANEL, browser()->profile())); |
| 105 function = new GetWindowFunction(); | 110 function = new GetWindowFunction(); |
| 111 function->set_extension(extension.get()); |
| 106 result.reset(utils::ToDictionary( | 112 result.reset(utils::ToDictionary( |
| 107 utils::RunFunctionAndReturnSingleResult( | 113 utils::RunFunctionAndReturnSingleResult( |
| 108 function.get(), | 114 function.get(), |
| 109 base::StringPrintf( | 115 base::StringPrintf( |
| 110 "[%u]", ExtensionTabUtil::GetWindowId(panel_browser)), | 116 "[%u]", ExtensionTabUtil::GetWindowId(panel_browser)), |
| 111 browser()))); | 117 browser()))); |
| 112 EXPECT_EQ("panel", utils::GetString(result.get(), "type")); | 118 EXPECT_EQ("panel", utils::GetString(result.get(), "type")); |
| 113 | 119 |
| 114 // Incognito. | 120 // Incognito. |
| 115 Browser* incognito_browser = CreateIncognitoBrowser(); | 121 Browser* incognito_browser = CreateIncognitoBrowser(); |
| 116 int incognito_window_id = ExtensionTabUtil::GetWindowId(incognito_browser); | 122 int incognito_window_id = ExtensionTabUtil::GetWindowId(incognito_browser); |
| 117 | 123 |
| 118 // Without "include_incognito". | 124 // Without "include_incognito". |
| 119 function = new GetWindowFunction(); | 125 function = new GetWindowFunction(); |
| 126 function->set_extension(extension.get()); |
| 120 EXPECT_TRUE(MatchPattern( | 127 EXPECT_TRUE(MatchPattern( |
| 121 utils::RunFunctionAndReturnError( | 128 utils::RunFunctionAndReturnError( |
| 122 function.get(), | 129 function.get(), |
| 123 base::StringPrintf("[%u]", incognito_window_id), | 130 base::StringPrintf("[%u]", incognito_window_id), |
| 124 browser()), | 131 browser()), |
| 125 keys::kWindowNotFoundError)); | 132 keys::kWindowNotFoundError)); |
| 126 | 133 |
| 127 // With "include_incognito". | 134 // With "include_incognito". |
| 128 function = new GetWindowFunction(); | 135 function = new GetWindowFunction(); |
| 136 function->set_extension(extension.get()); |
| 129 result.reset(utils::ToDictionary( | 137 result.reset(utils::ToDictionary( |
| 130 utils::RunFunctionAndReturnSingleResult( | 138 utils::RunFunctionAndReturnSingleResult( |
| 131 function.get(), | 139 function.get(), |
| 132 base::StringPrintf("[%u]", incognito_window_id), | 140 base::StringPrintf("[%u]", incognito_window_id), |
| 133 browser(), | 141 browser(), |
| 134 utils::INCLUDE_INCOGNITO))); | 142 utils::INCLUDE_INCOGNITO))); |
| 135 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito")); | 143 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito")); |
| 136 } | 144 } |
| 137 | 145 |
| 138 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetCurrentWindow) { | 146 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetCurrentWindow) { |
| 139 int window_id = ExtensionTabUtil::GetWindowId(browser()); | 147 int window_id = ExtensionTabUtil::GetWindowId(browser()); |
| 140 Browser* new_browser = CreateBrowser(browser()->profile()); | 148 Browser* new_browser = CreateBrowser(browser()->profile()); |
| 141 int new_id = ExtensionTabUtil::GetWindowId(new_browser); | 149 int new_id = ExtensionTabUtil::GetWindowId(new_browser); |
| 142 | 150 |
| 143 // Get the current window using new_browser. | 151 // Get the current window using new_browser. |
| 144 scoped_refptr<GetCurrentWindowFunction> function = | 152 scoped_refptr<GetCurrentWindowFunction> function = |
| 145 new GetCurrentWindowFunction(); | 153 new GetCurrentWindowFunction(); |
| 154 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension()); |
| 155 function->set_extension(extension.get()); |
| 146 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( | 156 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( |
| 147 utils::RunFunctionAndReturnSingleResult(function.get(), | 157 utils::RunFunctionAndReturnSingleResult(function.get(), |
| 148 "[]", | 158 "[]", |
| 149 new_browser))); | 159 new_browser))); |
| 150 | 160 |
| 151 // The id should match the window id of the browser instance that was passed | 161 // The id should match the window id of the browser instance that was passed |
| 152 // to RunFunctionAndReturnSingleResult. | 162 // to RunFunctionAndReturnSingleResult. |
| 153 EXPECT_EQ(new_id, utils::GetInteger(result.get(), "id")); | 163 EXPECT_EQ(new_id, utils::GetInteger(result.get(), "id")); |
| 154 ListValue* tabs = NULL; | 164 ListValue* tabs = NULL; |
| 155 EXPECT_FALSE(result.get()->GetList(keys::kTabsKey, &tabs)); | 165 EXPECT_FALSE(result.get()->GetList(keys::kTabsKey, &tabs)); |
| 156 | 166 |
| 157 // Get the current window using the old window and make the tabs populated. | 167 // Get the current window using the old window and make the tabs populated. |
| 158 function = new GetCurrentWindowFunction(); | 168 function = new GetCurrentWindowFunction(); |
| 169 function->set_extension(extension.get()); |
| 159 result.reset(utils::ToDictionary( | 170 result.reset(utils::ToDictionary( |
| 160 utils::RunFunctionAndReturnSingleResult(function.get(), | 171 utils::RunFunctionAndReturnSingleResult(function.get(), |
| 161 "[{\"populate\": true}]", | 172 "[{\"populate\": true}]", |
| 162 browser()))); | 173 browser()))); |
| 163 | 174 |
| 164 // The id should match the window id of the browser instance that was passed | 175 // The id should match the window id of the browser instance that was passed |
| 165 // to RunFunctionAndReturnSingleResult. | 176 // to RunFunctionAndReturnSingleResult. |
| 166 EXPECT_EQ(window_id, utils::GetInteger(result.get(), "id")); | 177 EXPECT_EQ(window_id, utils::GetInteger(result.get(), "id")); |
| 167 // "populate" was enabled so tabs should be populated. | 178 // "populate" was enabled so tabs should be populated. |
| 168 EXPECT_TRUE(result.get()->GetList(keys::kTabsKey, &tabs)); | 179 EXPECT_TRUE(result.get()->GetList(keys::kTabsKey, &tabs)); |
| 169 } | 180 } |
| 170 | 181 |
| 171 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetLastFocusedWindow) { | 182 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetLastFocusedWindow) { |
| 172 // Create a new window which making it the "last focused" window. | 183 // Create a new window which making it the "last focused" window. |
| 173 // Note that "last focused" means the "top" most window. | 184 // Note that "last focused" means the "top" most window. |
| 174 Browser* new_browser = CreateBrowser(browser()->profile()); | 185 Browser* new_browser = CreateBrowser(browser()->profile()); |
| 175 int focused_window_id = ExtensionTabUtil::GetWindowId(new_browser); | 186 int focused_window_id = ExtensionTabUtil::GetWindowId(new_browser); |
| 176 | 187 |
| 177 scoped_refptr<GetLastFocusedWindowFunction> function = | 188 scoped_refptr<GetLastFocusedWindowFunction> function = |
| 178 new GetLastFocusedWindowFunction(); | 189 new GetLastFocusedWindowFunction(); |
| 190 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension()); |
| 191 function->set_extension(extension.get()); |
| 179 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( | 192 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( |
| 180 utils::RunFunctionAndReturnSingleResult(function.get(), | 193 utils::RunFunctionAndReturnSingleResult(function.get(), |
| 181 "[]", | 194 "[]", |
| 182 new_browser))); | 195 new_browser))); |
| 183 | 196 |
| 184 // The id should always match the last focused window and does not depend | 197 // The id should always match the last focused window and does not depend |
| 185 // on what was passed to RunFunctionAndReturnSingleResult. | 198 // on what was passed to RunFunctionAndReturnSingleResult. |
| 186 EXPECT_EQ(focused_window_id, utils::GetInteger(result.get(), "id")); | 199 EXPECT_EQ(focused_window_id, utils::GetInteger(result.get(), "id")); |
| 187 ListValue* tabs = NULL; | 200 ListValue* tabs = NULL; |
| 188 EXPECT_FALSE(result.get()->GetList(keys::kTabsKey, &tabs)); | 201 EXPECT_FALSE(result.get()->GetList(keys::kTabsKey, &tabs)); |
| 189 | 202 |
| 190 function = new GetLastFocusedWindowFunction(); | 203 function = new GetLastFocusedWindowFunction(); |
| 204 function->set_extension(extension.get()); |
| 191 result.reset(utils::ToDictionary( | 205 result.reset(utils::ToDictionary( |
| 192 utils::RunFunctionAndReturnSingleResult(function.get(), | 206 utils::RunFunctionAndReturnSingleResult(function.get(), |
| 193 "[{\"populate\": true}]", | 207 "[{\"populate\": true}]", |
| 194 browser()))); | 208 browser()))); |
| 195 | 209 |
| 196 // The id should always match the last focused window and does not depend | 210 // The id should always match the last focused window and does not depend |
| 197 // on what was passed to RunFunctionAndReturnSingleResult. | 211 // on what was passed to RunFunctionAndReturnSingleResult. |
| 198 EXPECT_EQ(focused_window_id, utils::GetInteger(result.get(), "id")); | 212 EXPECT_EQ(focused_window_id, utils::GetInteger(result.get(), "id")); |
| 199 // "populate" was enabled so tabs should be populated. | 213 // "populate" was enabled so tabs should be populated. |
| 200 EXPECT_TRUE(result.get()->GetList(keys::kTabsKey, &tabs)); | 214 EXPECT_TRUE(result.get()->GetList(keys::kTabsKey, &tabs)); |
| 201 } | 215 } |
| 202 | 216 |
| 203 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetAllWindows) { | 217 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetAllWindows) { |
| 204 const size_t NUM_WINDOWS = 5; | 218 const size_t NUM_WINDOWS = 5; |
| 205 std::set<int> window_ids; | 219 std::set<int> window_ids; |
| 206 std::set<int> result_ids; | 220 std::set<int> result_ids; |
| 207 window_ids.insert(ExtensionTabUtil::GetWindowId(browser())); | 221 window_ids.insert(ExtensionTabUtil::GetWindowId(browser())); |
| 208 | 222 |
| 209 for (size_t i = 0; i < NUM_WINDOWS - 1; ++i) { | 223 for (size_t i = 0; i < NUM_WINDOWS - 1; ++i) { |
| 210 Browser* new_browser = CreateBrowser(browser()->profile()); | 224 Browser* new_browser = CreateBrowser(browser()->profile()); |
| 211 window_ids.insert(ExtensionTabUtil::GetWindowId(new_browser)); | 225 window_ids.insert(ExtensionTabUtil::GetWindowId(new_browser)); |
| 212 } | 226 } |
| 213 | 227 |
| 214 scoped_refptr<GetAllWindowsFunction> function = new GetAllWindowsFunction(); | 228 scoped_refptr<GetAllWindowsFunction> function = new GetAllWindowsFunction(); |
| 229 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension()); |
| 230 function->set_extension(extension.get()); |
| 215 scoped_ptr<base::ListValue> result(utils::ToList( | 231 scoped_ptr<base::ListValue> result(utils::ToList( |
| 216 utils::RunFunctionAndReturnSingleResult(function.get(), | 232 utils::RunFunctionAndReturnSingleResult(function.get(), |
| 217 "[]", | 233 "[]", |
| 218 browser()))); | 234 browser()))); |
| 219 | 235 |
| 220 ListValue* windows = result.get(); | 236 ListValue* windows = result.get(); |
| 221 EXPECT_EQ(NUM_WINDOWS, windows->GetSize()); | 237 EXPECT_EQ(NUM_WINDOWS, windows->GetSize()); |
| 222 for (size_t i = 0; i < NUM_WINDOWS; ++i) { | 238 for (size_t i = 0; i < NUM_WINDOWS; ++i) { |
| 223 DictionaryValue* result_window = NULL; | 239 DictionaryValue* result_window = NULL; |
| 224 EXPECT_TRUE(windows->GetDictionary(i, &result_window)); | 240 EXPECT_TRUE(windows->GetDictionary(i, &result_window)); |
| 225 result_ids.insert(utils::GetInteger(result_window, "id")); | 241 result_ids.insert(utils::GetInteger(result_window, "id")); |
| 226 | 242 |
| 227 // "populate" was not passed in so tabs are not populated. | 243 // "populate" was not passed in so tabs are not populated. |
| 228 ListValue* tabs = NULL; | 244 ListValue* tabs = NULL; |
| 229 EXPECT_FALSE(result_window->GetList(keys::kTabsKey, &tabs)); | 245 EXPECT_FALSE(result_window->GetList(keys::kTabsKey, &tabs)); |
| 230 } | 246 } |
| 231 // The returned ids should contain all the current browser instance ids. | 247 // The returned ids should contain all the current browser instance ids. |
| 232 EXPECT_EQ(window_ids, result_ids); | 248 EXPECT_EQ(window_ids, result_ids); |
| 233 | 249 |
| 234 result_ids.clear(); | 250 result_ids.clear(); |
| 235 function = new GetAllWindowsFunction(); | 251 function = new GetAllWindowsFunction(); |
| 252 function->set_extension(extension.get()); |
| 236 result.reset(utils::ToList( | 253 result.reset(utils::ToList( |
| 237 utils::RunFunctionAndReturnSingleResult(function.get(), | 254 utils::RunFunctionAndReturnSingleResult(function.get(), |
| 238 "[{\"populate\": true}]", | 255 "[{\"populate\": true}]", |
| 239 browser()))); | 256 browser()))); |
| 240 | 257 |
| 241 windows = result.get(); | 258 windows = result.get(); |
| 242 EXPECT_EQ(NUM_WINDOWS, windows->GetSize()); | 259 EXPECT_EQ(NUM_WINDOWS, windows->GetSize()); |
| 243 for (size_t i = 0; i < windows->GetSize(); ++i) { | 260 for (size_t i = 0; i < windows->GetSize(); ++i) { |
| 244 DictionaryValue* result_window = NULL; | 261 DictionaryValue* result_window = NULL; |
| 245 EXPECT_TRUE(windows->GetDictionary(i, &result_window)); | 262 EXPECT_TRUE(windows->GetDictionary(i, &result_window)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 256 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, UpdateNoPermissions) { | 273 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, UpdateNoPermissions) { |
| 257 // The test empty extension has no permissions, therefore it should not get | 274 // The test empty extension has no permissions, therefore it should not get |
| 258 // tab data in the function result. | 275 // tab data in the function result. |
| 259 scoped_refptr<UpdateTabFunction> update_tab_function(new UpdateTabFunction()); | 276 scoped_refptr<UpdateTabFunction> update_tab_function(new UpdateTabFunction()); |
| 260 scoped_refptr<extensions::Extension> empty_extension( | 277 scoped_refptr<extensions::Extension> empty_extension( |
| 261 utils::CreateEmptyExtension()); | 278 utils::CreateEmptyExtension()); |
| 262 update_tab_function->set_extension(empty_extension.get()); | 279 update_tab_function->set_extension(empty_extension.get()); |
| 263 // Without a callback the function will not generate a result. | 280 // Without a callback the function will not generate a result. |
| 264 update_tab_function->set_has_callback(true); | 281 update_tab_function->set_has_callback(true); |
| 265 | 282 |
| 266 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( | 283 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( |
| 284 utils::RunFunctionAndReturnSingleResult( |
| 267 update_tab_function.get(), | 285 update_tab_function.get(), |
| 268 "[null, {\"url\": \"neutrinos\"}]", | 286 "[null, {\"url\": \"about:blank\", \"pinned\": true}]", |
| 269 browser())); | 287 browser()))); |
| 270 EXPECT_EQ(base::Value::TYPE_NULL, result->GetType()); | 288 // The url is stripped since the extension does not have tab permissions. |
| 289 EXPECT_FALSE(result->HasKey("url")); |
| 290 EXPECT_TRUE(utils::GetBoolean(result.get(), "pinned")); |
| 271 } | 291 } |
| 272 | 292 |
| 273 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, | 293 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, |
| 274 DefaultToIncognitoWhenItIsForced) { | 294 DefaultToIncognitoWhenItIsForced) { |
| 275 static const char kArgsWithoutExplicitIncognitoParam[] = | 295 static const char kArgsWithoutExplicitIncognitoParam[] = |
| 276 "[{\"url\": \"about:blank\"}]"; | 296 "[{\"url\": \"about:blank\"}]"; |
| 277 // Force Incognito mode. | 297 // Force Incognito mode. |
| 278 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), | 298 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), |
| 279 IncognitoModePrefs::FORCED); | 299 IncognitoModePrefs::FORCED); |
| 280 // Run without an explicit "incognito" param. | 300 // Run without an explicit "incognito" param. |
| 281 scoped_refptr<CreateWindowFunction> function = new CreateWindowFunction(); | 301 scoped_refptr<CreateWindowFunction> function(new CreateWindowFunction()); |
| 302 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension()); |
| 303 function->set_extension(extension.get()); |
| 282 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( | 304 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( |
| 283 utils::RunFunctionAndReturnSingleResult( | 305 utils::RunFunctionAndReturnSingleResult( |
| 284 function.get(), | 306 function.get(), |
| 285 kArgsWithoutExplicitIncognitoParam, | 307 kArgsWithoutExplicitIncognitoParam, |
| 286 browser(), | 308 browser(), |
| 287 utils::INCLUDE_INCOGNITO))); | 309 utils::INCLUDE_INCOGNITO))); |
| 288 | 310 |
| 289 // Make sure it is a new(different) window. | 311 // Make sure it is a new(different) window. |
| 290 EXPECT_NE(ExtensionTabUtil::GetWindowId(browser()), | 312 EXPECT_NE(ExtensionTabUtil::GetWindowId(browser()), |
| 291 utils::GetInteger(result.get(), "id")); | 313 utils::GetInteger(result.get(), "id")); |
| 292 // ... and it is incognito. | 314 // ... and it is incognito. |
| 293 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito")); | 315 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito")); |
| 294 | 316 |
| 295 // Now try creating a window from incognito window. | 317 // Now try creating a window from incognito window. |
| 296 Browser* incognito_browser = CreateIncognitoBrowser(); | 318 Browser* incognito_browser = CreateIncognitoBrowser(); |
| 297 // Run without an explicit "incognito" param. | 319 // Run without an explicit "incognito" param. |
| 298 function = new CreateWindowFunction(); | 320 function = new CreateWindowFunction(); |
| 321 function->set_extension(extension.get()); |
| 299 result.reset(utils::ToDictionary( | 322 result.reset(utils::ToDictionary( |
| 300 utils::RunFunctionAndReturnSingleResult( | 323 utils::RunFunctionAndReturnSingleResult( |
| 301 function.get(), | 324 function.get(), |
| 302 kArgsWithoutExplicitIncognitoParam, | 325 kArgsWithoutExplicitIncognitoParam, |
| 303 incognito_browser, | 326 incognito_browser, |
| 304 utils::INCLUDE_INCOGNITO))); | 327 utils::INCLUDE_INCOGNITO))); |
| 305 // Make sure it is a new(different) window. | 328 // Make sure it is a new(different) window. |
| 306 EXPECT_NE(ExtensionTabUtil::GetWindowId(incognito_browser), | 329 EXPECT_NE(ExtensionTabUtil::GetWindowId(incognito_browser), |
| 307 utils::GetInteger(result.get(), "id")); | 330 utils::GetInteger(result.get(), "id")); |
| 308 // ... and it is incognito. | 331 // ... and it is incognito. |
| 309 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito")); | 332 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito")); |
| 310 } | 333 } |
| 311 | 334 |
| 312 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, | 335 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, |
| 313 DefaultToIncognitoWhenItIsForcedAndNoArgs) { | 336 DefaultToIncognitoWhenItIsForcedAndNoArgs) { |
| 314 static const char kEmptyArgs[] = "[]"; | 337 static const char kEmptyArgs[] = "[]"; |
| 315 // Force Incognito mode. | 338 // Force Incognito mode. |
| 316 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), | 339 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), |
| 317 IncognitoModePrefs::FORCED); | 340 IncognitoModePrefs::FORCED); |
| 318 // Run without an explicit "incognito" param. | 341 // Run without an explicit "incognito" param. |
| 319 scoped_refptr<CreateWindowFunction> function = new CreateWindowFunction(); | 342 scoped_refptr<CreateWindowFunction> function = new CreateWindowFunction(); |
| 343 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension()); |
| 344 function->set_extension(extension.get()); |
| 320 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( | 345 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( |
| 321 utils::RunFunctionAndReturnSingleResult(function.get(), | 346 utils::RunFunctionAndReturnSingleResult(function.get(), |
| 322 kEmptyArgs, | 347 kEmptyArgs, |
| 323 browser(), | 348 browser(), |
| 324 utils::INCLUDE_INCOGNITO))); | 349 utils::INCLUDE_INCOGNITO))); |
| 325 | 350 |
| 326 // Make sure it is a new(different) window. | 351 // Make sure it is a new(different) window. |
| 327 EXPECT_NE(ExtensionTabUtil::GetWindowId(browser()), | 352 EXPECT_NE(ExtensionTabUtil::GetWindowId(browser()), |
| 328 utils::GetInteger(result.get(), "id")); | 353 utils::GetInteger(result.get(), "id")); |
| 329 // ... and it is incognito. | 354 // ... and it is incognito. |
| 330 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito")); | 355 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito")); |
| 331 | 356 |
| 332 // Now try creating a window from incognito window. | 357 // Now try creating a window from incognito window. |
| 333 Browser* incognito_browser = CreateIncognitoBrowser(); | 358 Browser* incognito_browser = CreateIncognitoBrowser(); |
| 334 // Run without an explicit "incognito" param. | 359 // Run without an explicit "incognito" param. |
| 335 function = new CreateWindowFunction(); | 360 function = new CreateWindowFunction(); |
| 361 function->set_extension(extension.get()); |
| 336 result.reset(utils::ToDictionary( | 362 result.reset(utils::ToDictionary( |
| 337 utils::RunFunctionAndReturnSingleResult(function.get(), | 363 utils::RunFunctionAndReturnSingleResult(function.get(), |
| 338 kEmptyArgs, | 364 kEmptyArgs, |
| 339 incognito_browser, | 365 incognito_browser, |
| 340 utils::INCLUDE_INCOGNITO))); | 366 utils::INCLUDE_INCOGNITO))); |
| 341 // Make sure it is a new(different) window. | 367 // Make sure it is a new(different) window. |
| 342 EXPECT_NE(ExtensionTabUtil::GetWindowId(incognito_browser), | 368 EXPECT_NE(ExtensionTabUtil::GetWindowId(incognito_browser), |
| 343 utils::GetInteger(result.get(), "id")); | 369 utils::GetInteger(result.get(), "id")); |
| 344 // ... and it is incognito. | 370 // ... and it is incognito. |
| 345 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito")); | 371 EXPECT_TRUE(utils::GetBoolean(result.get(), "incognito")); |
| 346 } | 372 } |
| 347 | 373 |
| 348 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, | 374 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, |
| 349 DontCreateNormalWindowWhenIncognitoForced) { | 375 DontCreateNormalWindowWhenIncognitoForced) { |
| 350 static const char kArgsWithExplicitIncognitoParam[] = | 376 static const char kArgsWithExplicitIncognitoParam[] = |
| 351 "[{\"url\": \"about:blank\", \"incognito\": false }]"; | 377 "[{\"url\": \"about:blank\", \"incognito\": false }]"; |
| 352 // Force Incognito mode. | 378 // Force Incognito mode. |
| 353 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), | 379 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), |
| 354 IncognitoModePrefs::FORCED); | 380 IncognitoModePrefs::FORCED); |
| 355 | 381 |
| 356 // Run with an explicit "incognito" param. | 382 // Run with an explicit "incognito" param. |
| 357 scoped_refptr<CreateWindowFunction> function = new CreateWindowFunction(); | 383 scoped_refptr<CreateWindowFunction> function = new CreateWindowFunction(); |
| 384 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension()); |
| 385 function->set_extension(extension.get()); |
| 358 EXPECT_TRUE(MatchPattern( | 386 EXPECT_TRUE(MatchPattern( |
| 359 utils::RunFunctionAndReturnError(function.get(), | 387 utils::RunFunctionAndReturnError(function.get(), |
| 360 kArgsWithExplicitIncognitoParam, | 388 kArgsWithExplicitIncognitoParam, |
| 361 browser()), | 389 browser()), |
| 362 keys::kIncognitoModeIsForced)); | 390 keys::kIncognitoModeIsForced)); |
| 363 | 391 |
| 364 // Now try opening a normal window from incognito window. | 392 // Now try opening a normal window from incognito window. |
| 365 Browser* incognito_browser = CreateIncognitoBrowser(); | 393 Browser* incognito_browser = CreateIncognitoBrowser(); |
| 366 // Run with an explicit "incognito" param. | 394 // Run with an explicit "incognito" param. |
| 367 function = new CreateWindowFunction(); | 395 function = new CreateWindowFunction(); |
| 396 function->set_extension(extension.get()); |
| 368 EXPECT_TRUE(MatchPattern( | 397 EXPECT_TRUE(MatchPattern( |
| 369 utils::RunFunctionAndReturnError(function.get(), | 398 utils::RunFunctionAndReturnError(function.get(), |
| 370 kArgsWithExplicitIncognitoParam, | 399 kArgsWithExplicitIncognitoParam, |
| 371 incognito_browser), | 400 incognito_browser), |
| 372 keys::kIncognitoModeIsForced)); | 401 keys::kIncognitoModeIsForced)); |
| 373 } | 402 } |
| 374 | 403 |
| 375 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, | 404 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, |
| 376 DontCreateIncognitoWindowWhenIncognitoDisabled) { | 405 DontCreateIncognitoWindowWhenIncognitoDisabled) { |
| 377 static const char kArgs[] = | 406 static const char kArgs[] = |
| 378 "[{\"url\": \"about:blank\", \"incognito\": true }]"; | 407 "[{\"url\": \"about:blank\", \"incognito\": true }]"; |
| 379 | 408 |
| 380 Browser* incognito_browser = CreateIncognitoBrowser(); | 409 Browser* incognito_browser = CreateIncognitoBrowser(); |
| 381 // Disable Incognito mode. | 410 // Disable Incognito mode. |
| 382 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), | 411 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), |
| 383 IncognitoModePrefs::DISABLED); | 412 IncognitoModePrefs::DISABLED); |
| 384 // Run in normal window. | 413 // Run in normal window. |
| 385 scoped_refptr<CreateWindowFunction> function = new CreateWindowFunction(); | 414 scoped_refptr<CreateWindowFunction> function = new CreateWindowFunction(); |
| 415 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension()); |
| 416 function->set_extension(extension.get()); |
| 386 EXPECT_TRUE(MatchPattern( | 417 EXPECT_TRUE(MatchPattern( |
| 387 utils::RunFunctionAndReturnError(function.get(), | 418 utils::RunFunctionAndReturnError(function.get(), |
| 388 kArgs, | 419 kArgs, |
| 389 browser()), | 420 browser()), |
| 390 keys::kIncognitoModeIsDisabled)); | 421 keys::kIncognitoModeIsDisabled)); |
| 391 | 422 |
| 392 // Run in incognito window. | 423 // Run in incognito window. |
| 393 function = new CreateWindowFunction(); | 424 function = new CreateWindowFunction(); |
| 425 function->set_extension(extension.get()); |
| 394 EXPECT_TRUE(MatchPattern( | 426 EXPECT_TRUE(MatchPattern( |
| 395 utils::RunFunctionAndReturnError(function.get(), | 427 utils::RunFunctionAndReturnError(function.get(), |
| 396 kArgs, | 428 kArgs, |
| 397 incognito_browser), | 429 incognito_browser), |
| 398 keys::kIncognitoModeIsDisabled)); | 430 keys::kIncognitoModeIsDisabled)); |
| 399 } | 431 } |
| 400 | 432 |
| 401 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, QueryCurrentWindowTabs) { | 433 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, QueryCurrentWindowTabs) { |
| 402 const size_t kExtraWindows = 3; | 434 const size_t kExtraWindows = 3; |
| 403 for (size_t i = 0; i < kExtraWindows; ++i) | 435 for (size_t i = 0; i < kExtraWindows; ++i) |
| 404 CreateBrowser(browser()->profile()); | 436 CreateBrowser(browser()->profile()); |
| 405 | 437 |
| 406 GURL url; | 438 GURL url; |
| 407 AddTabAtIndexToBrowser(browser(), 0, url, content::PAGE_TRANSITION_LINK); | 439 AddTabAtIndexToBrowser(browser(), 0, url, content::PAGE_TRANSITION_LINK); |
| 408 int window_id = ExtensionTabUtil::GetWindowId(browser()); | 440 int window_id = ExtensionTabUtil::GetWindowId(browser()); |
| 409 | 441 |
| 410 // Get tabs in the 'current' window called from non-focused browser. | 442 // Get tabs in the 'current' window called from non-focused browser. |
| 411 scoped_refptr<QueryTabsFunction> function = new QueryTabsFunction(); | 443 scoped_refptr<QueryTabsFunction> function = new QueryTabsFunction(); |
| 444 function->set_extension(utils::CreateEmptyExtension().get()); |
| 412 scoped_ptr<base::ListValue> result(utils::ToList( | 445 scoped_ptr<base::ListValue> result(utils::ToList( |
| 413 utils::RunFunctionAndReturnSingleResult(function.get(), | 446 utils::RunFunctionAndReturnSingleResult(function.get(), |
| 414 "[{\"currentWindow\":true}]", | 447 "[{\"currentWindow\":true}]", |
| 415 browser()))); | 448 browser()))); |
| 416 | 449 |
| 417 ListValue* result_tabs = result.get(); | 450 ListValue* result_tabs = result.get(); |
| 418 // We should have one initial tab and one added tab. | 451 // We should have one initial tab and one added tab. |
| 419 EXPECT_EQ(2u, result_tabs->GetSize()); | 452 EXPECT_EQ(2u, result_tabs->GetSize()); |
| 420 for (size_t i = 0; i < result_tabs->GetSize(); ++i) { | 453 for (size_t i = 0; i < result_tabs->GetSize(); ++i) { |
| 421 DictionaryValue* result_tab = NULL; | 454 DictionaryValue* result_tab = NULL; |
| 422 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); | 455 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); |
| 423 EXPECT_EQ(window_id, utils::GetInteger(result_tab, keys::kWindowIdKey)); | 456 EXPECT_EQ(window_id, utils::GetInteger(result_tab, keys::kWindowIdKey)); |
| 424 } | 457 } |
| 425 | 458 |
| 426 // Get tabs NOT in the 'current' window called from non-focused browser. | 459 // Get tabs NOT in the 'current' window called from non-focused browser. |
| 427 function = new QueryTabsFunction(); | 460 function = new QueryTabsFunction(); |
| 461 function->set_extension(utils::CreateEmptyExtension().get()); |
| 428 result.reset(utils::ToList( | 462 result.reset(utils::ToList( |
| 429 utils::RunFunctionAndReturnSingleResult(function.get(), | 463 utils::RunFunctionAndReturnSingleResult(function.get(), |
| 430 "[{\"currentWindow\":false}]", | 464 "[{\"currentWindow\":false}]", |
| 431 browser()))); | 465 browser()))); |
| 432 | 466 |
| 433 result_tabs = result.get(); | 467 result_tabs = result.get(); |
| 434 // We should have one tab for each extra window. | 468 // We should have one tab for each extra window. |
| 435 EXPECT_EQ(kExtraWindows, result_tabs->GetSize()); | 469 EXPECT_EQ(kExtraWindows, result_tabs->GetSize()); |
| 436 for (size_t i = 0; i < kExtraWindows; ++i) { | 470 for (size_t i = 0; i < kExtraWindows; ++i) { |
| 437 DictionaryValue* result_tab = NULL; | 471 DictionaryValue* result_tab = NULL; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DontCreateTabInClosingPopupWindow) { | 533 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DontCreateTabInClosingPopupWindow) { |
| 500 // Test creates new popup window, closes it right away and then tries to open | 534 // Test creates new popup window, closes it right away and then tries to open |
| 501 // a new tab in it. Tab should not be opened in the popup window, but in a | 535 // a new tab in it. Tab should not be opened in the popup window, but in a |
| 502 // tabbed browser window. | 536 // tabbed browser window. |
| 503 Browser* popup_browser = new Browser( | 537 Browser* popup_browser = new Browser( |
| 504 Browser::CreateParams(Browser::TYPE_POPUP, browser()->profile())); | 538 Browser::CreateParams(Browser::TYPE_POPUP, browser()->profile())); |
| 505 int window_id = ExtensionTabUtil::GetWindowId(popup_browser); | 539 int window_id = ExtensionTabUtil::GetWindowId(popup_browser); |
| 506 chrome::CloseWindow(popup_browser); | 540 chrome::CloseWindow(popup_browser); |
| 507 | 541 |
| 508 scoped_refptr<CreateTabFunction> create_tab_function(new CreateTabFunction()); | 542 scoped_refptr<CreateTabFunction> create_tab_function(new CreateTabFunction()); |
| 543 create_tab_function->set_extension(utils::CreateEmptyExtension().get()); |
| 509 // Without a callback the function will not generate a result. | 544 // Without a callback the function will not generate a result. |
| 510 create_tab_function->set_has_callback(true); | 545 create_tab_function->set_has_callback(true); |
| 511 | 546 |
| 512 static const char kNewBlankTabArgs[] = | 547 static const char kNewBlankTabArgs[] = |
| 513 "[{\"url\": \"about:blank\", \"windowId\": %u}]"; | 548 "[{\"url\": \"about:blank\", \"windowId\": %u}]"; |
| 514 | 549 |
| 515 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( | 550 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( |
| 516 utils::RunFunctionAndReturnSingleResult( | 551 utils::RunFunctionAndReturnSingleResult( |
| 517 create_tab_function.get(), | 552 create_tab_function.get(), |
| 518 base::StringPrintf(kNewBlankTabArgs, window_id), | 553 base::StringPrintf(kNewBlankTabArgs, window_id), |
| 519 browser()))); | 554 browser()))); |
| 520 | 555 |
| 521 EXPECT_NE(window_id, utils::GetInteger(result.get(), "windowId")); | 556 EXPECT_NE(window_id, utils::GetInteger(result.get(), "windowId")); |
| 522 } | 557 } |
| 523 | 558 |
| 524 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, InvalidUpdateWindowState) { | 559 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, InvalidUpdateWindowState) { |
| 525 int window_id = ExtensionTabUtil::GetWindowId(browser()); | 560 int window_id = ExtensionTabUtil::GetWindowId(browser()); |
| 526 | 561 |
| 527 static const char kArgsMinimizedWithFocus[] = | 562 static const char kArgsMinimizedWithFocus[] = |
| 528 "[%u, {\"state\": \"minimized\", \"focused\": true}]"; | 563 "[%u, {\"state\": \"minimized\", \"focused\": true}]"; |
| 529 scoped_refptr<UpdateWindowFunction> function = new UpdateWindowFunction(); | 564 scoped_refptr<UpdateWindowFunction> function = new UpdateWindowFunction(); |
| 565 scoped_refptr<extensions::Extension> extension(utils::CreateEmptyExtension()); |
| 566 function->set_extension(extension.get()); |
| 530 EXPECT_TRUE(MatchPattern( | 567 EXPECT_TRUE(MatchPattern( |
| 531 utils::RunFunctionAndReturnError( | 568 utils::RunFunctionAndReturnError( |
| 532 function.get(), | 569 function.get(), |
| 533 base::StringPrintf(kArgsMinimizedWithFocus, window_id), | 570 base::StringPrintf(kArgsMinimizedWithFocus, window_id), |
| 534 browser()), | 571 browser()), |
| 535 keys::kInvalidWindowStateError)); | 572 keys::kInvalidWindowStateError)); |
| 536 | 573 |
| 537 static const char kArgsMaximizedWithoutFocus[] = | 574 static const char kArgsMaximizedWithoutFocus[] = |
| 538 "[%u, {\"state\": \"maximized\", \"focused\": false}]"; | 575 "[%u, {\"state\": \"maximized\", \"focused\": false}]"; |
| 539 function = new UpdateWindowFunction(); | 576 function = new UpdateWindowFunction(); |
| 577 function->set_extension(extension.get()); |
| 540 EXPECT_TRUE(MatchPattern( | 578 EXPECT_TRUE(MatchPattern( |
| 541 utils::RunFunctionAndReturnError( | 579 utils::RunFunctionAndReturnError( |
| 542 function.get(), | 580 function.get(), |
| 543 base::StringPrintf(kArgsMaximizedWithoutFocus, window_id), | 581 base::StringPrintf(kArgsMaximizedWithoutFocus, window_id), |
| 544 browser()), | 582 browser()), |
| 545 keys::kInvalidWindowStateError)); | 583 keys::kInvalidWindowStateError)); |
| 546 | 584 |
| 547 static const char kArgsMinimizedWithBounds[] = | 585 static const char kArgsMinimizedWithBounds[] = |
| 548 "[%u, {\"state\": \"minimized\", \"width\": 500}]"; | 586 "[%u, {\"state\": \"minimized\", \"width\": 500}]"; |
| 549 function = new UpdateWindowFunction(); | 587 function = new UpdateWindowFunction(); |
| 588 function->set_extension(extension.get()); |
| 550 EXPECT_TRUE(MatchPattern( | 589 EXPECT_TRUE(MatchPattern( |
| 551 utils::RunFunctionAndReturnError( | 590 utils::RunFunctionAndReturnError( |
| 552 function.get(), | 591 function.get(), |
| 553 base::StringPrintf(kArgsMinimizedWithBounds, window_id), | 592 base::StringPrintf(kArgsMinimizedWithBounds, window_id), |
| 554 browser()), | 593 browser()), |
| 555 keys::kInvalidWindowStateError)); | 594 keys::kInvalidWindowStateError)); |
| 556 | 595 |
| 557 static const char kArgsMaximizedWithBounds[] = | 596 static const char kArgsMaximizedWithBounds[] = |
| 558 "[%u, {\"state\": \"maximized\", \"width\": 500}]"; | 597 "[%u, {\"state\": \"maximized\", \"width\": 500}]"; |
| 559 function = new UpdateWindowFunction(); | 598 function = new UpdateWindowFunction(); |
| 599 function->set_extension(extension.get()); |
| 560 EXPECT_TRUE(MatchPattern( | 600 EXPECT_TRUE(MatchPattern( |
| 561 utils::RunFunctionAndReturnError( | 601 utils::RunFunctionAndReturnError( |
| 562 function.get(), | 602 function.get(), |
| 563 base::StringPrintf(kArgsMaximizedWithBounds, window_id), | 603 base::StringPrintf(kArgsMaximizedWithBounds, window_id), |
| 564 browser()), | 604 browser()), |
| 565 keys::kInvalidWindowStateError)); | 605 keys::kInvalidWindowStateError)); |
| 566 } | 606 } |
| OLD | NEW |