OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 #include "base/strings/stringprintf.h" |
5 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
6 #include "chrome/browser/extensions/api/tabs/tabs_api.h" | 7 #include "chrome/browser/extensions/api/tabs/tabs_api.h" |
7 #include "chrome/browser/extensions/extension_function_test_utils.h" | 8 #include "chrome/browser/extensions/extension_function_test_utils.h" |
8 #include "chrome/browser/extensions/extension_service_test_base.h" | 9 #include "chrome/browser/extensions/extension_service_test_base.h" |
9 #include "chrome/browser/extensions/extension_tab_util.h" | 10 #include "chrome/browser/extensions/extension_tab_util.h" |
| 11 #include "chrome/browser/sessions/session_tab_helper.h" |
10 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
12 #include "chrome/test/base/test_browser_window.h" | 14 #include "chrome/test/base/test_browser_window.h" |
13 #include "content/public/browser/navigation_entry.h" | 15 #include "content/public/browser/navigation_entry.h" |
14 #include "content/public/common/browser_side_navigation_policy.h" | 16 #include "content/public/common/browser_side_navigation_policy.h" |
15 #include "content/public/test/browser_side_navigation_test_utils.h" | 17 #include "content/public/test/browser_side_navigation_test_utils.h" |
16 #include "content/public/test/web_contents_tester.h" | 18 #include "content/public/test/web_contents_tester.h" |
| 19 #include "extensions/browser/api_test_utils.h" |
17 #include "extensions/common/extension_builder.h" | 20 #include "extensions/common/extension_builder.h" |
18 #include "extensions/common/test_util.h" | 21 #include "extensions/common/test_util.h" |
19 | 22 |
20 namespace extensions { | 23 namespace extensions { |
21 | 24 |
22 namespace { | 25 namespace { |
23 | 26 |
24 std::unique_ptr<base::ListValue> RunTabsQueryFunction( | 27 std::unique_ptr<base::ListValue> RunTabsQueryFunction( |
25 Browser* browser, | 28 Browser* browser, |
26 const Extension* extension, | 29 const Extension* extension, |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 int first_tab_id = -1; | 212 int first_tab_id = -1; |
210 ASSERT_TRUE(first_tab_info->GetInteger("id", &first_tab_id)); | 213 ASSERT_TRUE(first_tab_info->GetInteger("id", &first_tab_id)); |
211 EXPECT_TRUE(base::ContainsValue(expected_tabs_ids, first_tab_id)); | 214 EXPECT_TRUE(base::ContainsValue(expected_tabs_ids, first_tab_id)); |
212 | 215 |
213 int third_tab_id = -1; | 216 int third_tab_id = -1; |
214 ASSERT_TRUE(third_tab_info->GetInteger("id", &third_tab_id)); | 217 ASSERT_TRUE(third_tab_info->GetInteger("id", &third_tab_id)); |
215 EXPECT_TRUE(base::ContainsValue(expected_tabs_ids, third_tab_id)); | 218 EXPECT_TRUE(base::ContainsValue(expected_tabs_ids, third_tab_id)); |
216 } | 219 } |
217 } | 220 } |
218 | 221 |
| 222 // Test that using the PDF extension for tab updates is treated as a |
| 223 // renderer-initiated navigation. crbug.com/660498 |
| 224 TEST_F(TabsApiUnitTest, PDFExtensionNavigation) { |
| 225 DictionaryBuilder manifest; |
| 226 manifest.Set("name", "pdfext") |
| 227 .Set("description", "desc") |
| 228 .Set("version", "0.1") |
| 229 .Set("manifest_version", 2) |
| 230 .Set("permissions", ListBuilder().Append("tabs").Build()); |
| 231 scoped_refptr<const Extension> extension = |
| 232 ExtensionBuilder() |
| 233 .SetManifest(manifest.Build()) |
| 234 .SetID(extension_misc::kPdfExtensionId) |
| 235 .Build(); |
| 236 ASSERT_TRUE(extension); |
| 237 |
| 238 content::WebContents* web_contents = |
| 239 content::WebContentsTester::CreateTestWebContents(profile(), nullptr); |
| 240 ASSERT_TRUE(web_contents); |
| 241 content::WebContentsTester* web_contents_tester = |
| 242 content::WebContentsTester::For(web_contents); |
| 243 const GURL kGoogle("http://www.google.com"); |
| 244 web_contents_tester->NavigateAndCommit(kGoogle); |
| 245 EXPECT_EQ(kGoogle, web_contents->GetLastCommittedURL()); |
| 246 EXPECT_EQ(kGoogle, web_contents->GetVisibleURL()); |
| 247 |
| 248 SessionTabHelper::CreateForWebContents(web_contents); |
| 249 int tab_id = SessionTabHelper::IdForTab(web_contents); |
| 250 browser()->tab_strip_model()->AppendWebContents(web_contents, true); |
| 251 |
| 252 scoped_refptr<TabsUpdateFunction> function = new TabsUpdateFunction(); |
| 253 function->set_extension(extension.get()); |
| 254 function->set_browser_context(profile()); |
| 255 std::unique_ptr<base::ListValue> args( |
| 256 extension_function_test_utils::ParseList(base::StringPrintf( |
| 257 "[%d, {\"url\":\"http://example.com\"}]", tab_id))); |
| 258 function->SetArgs(args.get()); |
| 259 api_test_utils::SendResponseHelper response_helper(function.get()); |
| 260 function->RunWithValidation()->Execute(); |
| 261 |
| 262 EXPECT_EQ(kGoogle, web_contents->GetLastCommittedURL()); |
| 263 EXPECT_EQ(kGoogle, web_contents->GetVisibleURL()); |
| 264 |
| 265 // Clean up. |
| 266 response_helper.WaitForResponse(); |
| 267 while (!browser()->tab_strip_model()->empty()) |
| 268 browser()->tab_strip_model()->CloseWebContentsAt(0, 0); |
| 269 base::RunLoop().RunUntilIdle(); |
| 270 } |
| 271 |
219 } // namespace extensions | 272 } // namespace extensions |
OLD | NEW |