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

Side by Side Diff: chrome/browser/extensions/webstore_inline_installer_browsertest.cc

Issue 2831263003: Gate sending referrers to CWS on whether the profile has SafeBrowsing enabled. (Closed)
Patch Set: Devlin feedback. Created 3 years, 8 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
« no previous file with comments | « chrome/browser/extensions/webstore_inline_installer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/webstore_inline_installer.h" 5 #include "chrome/browser/extensions/webstore_inline_installer.h"
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 12 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
13 #include "chrome/browser/extensions/extension_install_prompt.h" 13 #include "chrome/browser/extensions/extension_install_prompt.h"
14 #include "chrome/browser/extensions/extension_service.h" 14 #include "chrome/browser/extensions/extension_service.h"
15 #include "chrome/browser/extensions/tab_helper.h" 15 #include "chrome/browser/extensions/tab_helper.h"
16 #include "chrome/browser/extensions/webstore_inline_installer_factory.h" 16 #include "chrome/browser/extensions/webstore_inline_installer_factory.h"
17 #include "chrome/browser/extensions/webstore_installer_test.h" 17 #include "chrome/browser/extensions/webstore_installer_test.h"
18 #include "chrome/browser/extensions/webstore_standalone_installer.h" 18 #include "chrome/browser/extensions/webstore_standalone_installer.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_finder.h" 21 #include "chrome/browser/ui/browser_finder.h"
22 #include "chrome/browser/ui/tabs/tab_strip_model.h" 22 #include "chrome/browser/ui/tabs/tab_strip_model.h"
23 #include "chrome/common/pref_names.h"
23 #include "chrome/test/base/ui_test_utils.h" 24 #include "chrome/test/base/ui_test_utils.h"
24 #include "components/content_settings/core/browser/host_content_settings_map.h" 25 #include "components/content_settings/core/browser/host_content_settings_map.h"
26 #include "components/prefs/pref_service.h"
25 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
26 #include "content/public/test/browser_test_utils.h" 28 #include "content/public/test/browser_test_utils.h"
27 #include "extensions/browser/extension_registry.h" 29 #include "extensions/browser/extension_registry.h"
28 #include "extensions/browser/extension_system.h" 30 #include "extensions/browser/extension_system.h"
29 #include "extensions/common/permissions/permission_set.h" 31 #include "extensions/common/permissions/permission_set.h"
30 #include "net/dns/mock_host_resolver.h" 32 #include "net/dns/mock_host_resolver.h"
31 #include "net/test/embedded_test_server/http_request.h" 33 #include "net/test/embedded_test_server/http_request.h"
32 #include "url/gurl.h" 34 #include "url/gurl.h"
33 35
34 using content::WebContents; 36 using content::WebContents;
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 ~WebstoreInlineInstallerRedirectTest() override {} 379 ~WebstoreInlineInstallerRedirectTest() override {}
378 380
379 void SetUpInProcessBrowserTestFixture() override { 381 void SetUpInProcessBrowserTestFixture() override {
380 WebstoreInstallerTest::SetUpInProcessBrowserTestFixture(); 382 WebstoreInstallerTest::SetUpInProcessBrowserTestFixture();
381 host_resolver()->AddRule(kRedirect1Domain, "127.0.0.1"); 383 host_resolver()->AddRule(kRedirect1Domain, "127.0.0.1");
382 host_resolver()->AddRule(kRedirect2Domain, "127.0.0.1"); 384 host_resolver()->AddRule(kRedirect2Domain, "127.0.0.1");
383 } 385 }
384 386
385 void ProcessServerRequest( 387 void ProcessServerRequest(
386 const net::test_server::HttpRequest& request) override { 388 const net::test_server::HttpRequest& request) override {
389 cws_request_received_ = true;
387 if (request.content.find("redirect_chain") != std::string::npos) { 390 if (request.content.find("redirect_chain") != std::string::npos) {
388 cws_request_received_ = true;
389
390 std::unique_ptr<base::Value> contents = 391 std::unique_ptr<base::Value> contents =
391 base::JSONReader::Read(request.content); 392 base::JSONReader::Read(request.content);
392 ASSERT_EQ(base::Value::Type::DICTIONARY, contents->GetType()); 393 ASSERT_EQ(base::Value::Type::DICTIONARY, contents->GetType());
393 cws_request_json_data_ = base::DictionaryValue::From(std::move(contents)); 394 cws_request_json_data_ = base::DictionaryValue::From(std::move(contents));
394 } 395 }
395 } 396 }
396 397
397 bool cws_request_received_; 398 bool cws_request_received_;
398 std::unique_ptr<base::DictionaryValue> cws_request_json_data_; 399 std::unique_ptr<base::DictionaryValue> cws_request_json_data_;
399 }; 400 };
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 ASSERT_EQ(expected_redirect_domains.size(), redirect_list->GetSize()); 434 ASSERT_EQ(expected_redirect_domains.size(), redirect_list->GetSize());
434 int i = 0; 435 int i = 0;
435 for (const auto& value : *redirect_list) { 436 for (const auto& value : *redirect_list) {
436 std::string value_string; 437 std::string value_string;
437 ASSERT_TRUE(value.GetAsString(&value_string)); 438 ASSERT_TRUE(value.GetAsString(&value_string));
438 GURL redirect_url(value_string); 439 GURL redirect_url(value_string);
439 EXPECT_EQ(expected_redirect_domains[i++], redirect_url.host()); 440 EXPECT_EQ(expected_redirect_domains[i++], redirect_url.host());
440 } 441 }
441 } 442 }
442 443
444 // Test that an install from a page arrived at via redirects does not include
445 // redirect information when SafeBrowsing is disabled.
446 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerRedirectTest,
447 NoRedirectDataWhenSafeBrowsingDisabled) {
448 PrefService* pref_service = browser()->profile()->GetPrefs();
449 EXPECT_TRUE(pref_service->GetBoolean(prefs::kSafeBrowsingEnabled));
450
451 // Disable SafeBrowsing.
452 pref_service->SetBoolean(prefs::kSafeBrowsingEnabled, false);
453
454 // Hand craft a url that will cause the test server to issue redirects.
455 const std::vector<std::string> redirects = {kRedirect1Domain,
456 kRedirect2Domain};
457 net::HostPortPair host_port = embedded_test_server()->host_port_pair();
458 std::string redirect_chain;
459 for (const auto& redirect : redirects) {
460 std::string redirect_url = base::StringPrintf(
461 "http://%s:%d/server-redirect?", redirect.c_str(), host_port.port());
462 redirect_chain += redirect_url;
463 }
464 const GURL install_url =
465 GURL(redirect_chain +
466 GenerateTestServerUrl(kAppDomain, "install.html").spec());
467
468 AutoAcceptInstall();
469 ui_test_utils::NavigateToURL(browser(), install_url);
470 RunTest("runTest");
471
472 EXPECT_TRUE(cws_request_received_);
473 ASSERT_EQ(nullptr, cws_request_json_data_);
474 }
475
443 class WebstoreInlineInstallerListenerTest : public WebstoreInlineInstallerTest { 476 class WebstoreInlineInstallerListenerTest : public WebstoreInlineInstallerTest {
444 public: 477 public:
445 WebstoreInlineInstallerListenerTest() {} 478 WebstoreInlineInstallerListenerTest() {}
446 ~WebstoreInlineInstallerListenerTest() override {} 479 ~WebstoreInlineInstallerListenerTest() override {}
447 480
448 protected: 481 protected:
449 void RunTest(const std::string& file_name) { 482 void RunTest(const std::string& file_name) {
450 AutoAcceptInstall(); 483 AutoAcceptInstall();
451 ui_test_utils::NavigateToURL(browser(), 484 ui_test_utils::NavigateToURL(browser(),
452 GenerateTestServerUrl(kAppDomain, file_name)); 485 GenerateTestServerUrl(kAppDomain, file_name));
(...skipping 30 matching lines...) Expand all
483 WindowOpenDisposition::NEW_FOREGROUND_TAB, 516 WindowOpenDisposition::NEW_FOREGROUND_TAB,
484 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 517 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
485 DCHECK_NE(old_tab_index, browser()->tab_strip_model()->active_index()); 518 DCHECK_NE(old_tab_index, browser()->tab_strip_model()->active_index());
486 browser()->tab_strip_model()->CloseWebContentsAt(old_tab_index, 519 browser()->tab_strip_model()->CloseWebContentsAt(old_tab_index,
487 TabStripModel::CLOSE_NONE); 520 TabStripModel::CLOSE_NONE);
488 WebstoreInstallerTest::RunTest("runTest"); 521 WebstoreInstallerTest::RunTest("runTest");
489 EXPECT_TRUE(registry->enabled_extensions().GetByID(kTestExtensionId)); 522 EXPECT_TRUE(registry->enabled_extensions().GetByID(kTestExtensionId));
490 } 523 }
491 524
492 } // namespace extensions 525 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/webstore_inline_installer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698