Chromium Code Reviews| Index: chrome/browser/extensions/webstore_inline_installer_browsertest.cc |
| diff --git a/chrome/browser/extensions/webstore_inline_installer_browsertest.cc b/chrome/browser/extensions/webstore_inline_installer_browsertest.cc |
| index 5ae1fef25b502cbf5e6f054515e27b3e6612fa2b..458c90f80a6f3e76277c67a40feca2c4ba48f16b 100644 |
| --- a/chrome/browser/extensions/webstore_inline_installer_browsertest.cc |
| +++ b/chrome/browser/extensions/webstore_inline_installer_browsertest.cc |
| @@ -4,9 +4,11 @@ |
| #include "chrome/browser/extensions/webstore_inline_installer.h" |
| +#include "base/json/json_reader.h" |
| #include "base/macros.h" |
| #include "base/memory/ptr_util.h" |
| #include "base/strings/utf_string_conversions.h" |
| +#include "base/values.h" |
| #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| #include "chrome/browser/extensions/extension_install_prompt.h" |
| #include "chrome/browser/extensions/extension_service.h" |
| @@ -25,9 +27,12 @@ |
| #include "extensions/browser/extension_registry.h" |
| #include "extensions/browser/extension_system.h" |
| #include "extensions/common/permissions/permission_set.h" |
| +#include "net/dns/mock_host_resolver.h" |
| +#include "net/test/embedded_test_server/http_request.h" |
| #include "url/gurl.h" |
| using content::WebContents; |
| +using net::test_server::HttpRequest; |
|
Devlin
2017/01/27 20:31:34
nit: avoid using 'using' for single uses. :)
robertshield
2017/01/28 03:58:48
Done.
|
| namespace extensions { |
| @@ -40,6 +45,9 @@ const char kTestExtensionId[] = "ecglahbcnmdpdciemllbhojghbkagdje"; |
| const char kTestDataPath[] = "extensions/api_test/webstore_inline_install"; |
| const char kCrxFilename[] = "extension.crx"; |
| +const char kRedirect1Domain[] = "redirect1.com"; |
| +const char kRedirect2Domain[] = "redirect2.com"; |
| + |
| // A struct for letting us store the actual parameters that were passed to |
| // the install callback. |
| struct InstallResult { |
| @@ -363,6 +371,69 @@ IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest, DoubleInlineInstallTest) { |
| RunTest("runTest"); |
| } |
| +class WebstoreInlineInstallerRedirectTest : public WebstoreInlineInstallerTest { |
| + public: |
| + WebstoreInlineInstallerRedirectTest() |
| + : cws_request_received_(false), cws_request_redirects_(0) {} |
| + ~WebstoreInlineInstallerRedirectTest() override {} |
| + |
| + void SetUpInProcessBrowserTestFixture() override { |
| + WebstoreInstallerTest::SetUpInProcessBrowserTestFixture(); |
| + host_resolver()->AddRule(kRedirect1Domain, "127.0.0.1"); |
| + host_resolver()->AddRule(kRedirect2Domain, "127.0.0.1"); |
| + } |
| + |
| + void ProcessServerRequest(const HttpRequest& request) override { |
| + if (request.content.find("redirect_chain") != std::string::npos) { |
| + cws_request_received_ = true; |
| + |
| + std::unique_ptr<base::Value> contents = |
| + base::JSONReader::Read(request.content); |
| + base::DictionaryValue* contents_dict = nullptr; |
| + contents->GetAsDictionary(&contents_dict); |
| + if (contents_dict) { |
| + base::ListValue* redirect_chain = nullptr; |
| + contents_dict->GetList("redirect_chain", &redirect_chain); |
| + if (redirect_chain) { |
| + cws_request_redirects_ = redirect_chain->GetSize(); |
| + } |
| + } |
| + } |
| + } |
| + |
| + bool cws_request_received_; |
| + int cws_request_redirects_; |
| +}; |
| + |
| +// Test that an install from a page arrived at via redirects includes the |
| +// redirect information in the webstore request. |
| +IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerRedirectTest, |
| + IncludesRedirectData) { |
| + // Hand craft a url that will cause the test server to issue redirects. |
| + const std::vector<std::string> redirects{kRedirect1Domain, kRedirect2Domain}; |
| + |
| + net::HostPortPair host_port = embedded_test_server()->host_port_pair(); |
| + |
| + std::string redirect_chain; |
| + for (auto redirect : redirects) { |
|
Devlin
2017/01/27 20:31:34
const auto&
robertshield
2017/01/28 03:58:48
Done.
|
| + std::string redir = base::StringPrintf("http://%s:%d/server-redirect?", |
|
Devlin
2017/01/27 20:31:34
maybe s/redir/url or redirect_url?
robertshield
2017/01/28 03:58:48
Done.
|
| + redirect.c_str(), host_port.port()); |
| + redirect_chain += redir; |
| + } |
| + const GURL install_url = |
| + GURL(redirect_chain + |
| + GenerateTestServerUrl(kAppDomain, "install.html").spec()); |
| + |
| + AutoAcceptInstall(); |
| + ui_test_utils::NavigateToURL(browser(), install_url); |
| + RunTest("runTest"); |
| + |
| + EXPECT_TRUE(cws_request_received_); |
| + // Three items, two for the items in |redirects| and one more for the final |
| + // install url. |
| + EXPECT_EQ(3, cws_request_redirects_); |
|
Devlin
2017/01/27 20:31:34
It'd be nice to verify the contents, too. Maybe j
robertshield
2017/01/28 03:58:48
Done.
|
| +} |
| + |
| class WebstoreInlineInstallerListenerTest : public WebstoreInlineInstallerTest { |
| public: |
| WebstoreInlineInstallerListenerTest() {} |