Chromium Code Reviews| Index: chrome/browser/extensions/updater/extension_updater_unittest.cc |
| diff --git a/chrome/browser/extensions/updater/extension_updater_unittest.cc b/chrome/browser/extensions/updater/extension_updater_unittest.cc |
| index 95b169740881046af3c8d68cbdc350cb8b0636d6..ee5c45f601687e769df20edc5ab55c82eaf5ac14 100644 |
| --- a/chrome/browser/extensions/updater/extension_updater_unittest.cc |
| +++ b/chrome/browser/extensions/updater/extension_updater_unittest.cc |
| @@ -765,7 +765,7 @@ class ExtensionUpdaterTest : public testing::Test { |
| std::unique_ptr<ManifestFetchData> fetch_data( |
| CreateManifestFetchData(GURL("http://localhost/foo"))); |
| fetch_data->AddExtension(id, version, &kNeverPingedData, std::string(), |
| - std::string()); |
| + std::string(), false); |
| std::map<std::string, std::string> params; |
| VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); |
| @@ -783,7 +783,7 @@ class ExtensionUpdaterTest : public testing::Test { |
| std::unique_ptr<ManifestFetchData> fetch_data( |
| CreateManifestFetchData(GURL("http://localhost/foo"))); |
| fetch_data->AddExtension(id, version, &kNeverPingedData, "bar", |
| - std::string()); |
| + std::string(), false); |
| std::map<std::string, std::string> params; |
| VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); |
| EXPECT_EQ(id, params["id"]); |
| @@ -800,7 +800,7 @@ class ExtensionUpdaterTest : public testing::Test { |
| std::unique_ptr<ManifestFetchData> fetch_data( |
| CreateManifestFetchData(GURL("http://localhost/foo"))); |
| fetch_data->AddExtension(id, version, &kNeverPingedData, "a=1&b=2&c", |
| - std::string()); |
| + std::string(), false); |
| std::map<std::string, std::string> params; |
| VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); |
| EXPECT_EQ(id, params["id"]); |
| @@ -808,7 +808,8 @@ class ExtensionUpdaterTest : public testing::Test { |
| EXPECT_EQ("a%3D1%26b%3D2%26c", params["ap"]); |
| } |
| - void TestUpdateUrlDataFromGallery(const std::string& gallery_url) { |
| + void TestUpdateUrlDataFromGallery(const std::string& gallery_url, |
| + bool foreground_check) { |
| net::TestURLFetcherFactory factory; |
| MockService service(prefs_.get()); |
| @@ -822,7 +823,7 @@ class ExtensionUpdaterTest : public testing::Test { |
| const std::string& id = extensions[0]->id(); |
| EXPECT_CALL(delegate, GetPingDataForExtension(id, _)); |
| - downloader.AddExtension(*extensions[0], 0); |
| + downloader.AddExtension(*extensions[0], 0, foreground_check); |
| downloader.StartAllPending(NULL); |
| net::TestURLFetcher* fetcher = |
| factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); |
| @@ -834,6 +835,33 @@ class ExtensionUpdaterTest : public testing::Test { |
| EXPECT_NE(std::string::npos, x); |
| std::string::size_type ap = update_url.find("ap%3D", x); |
| EXPECT_EQ(std::string::npos, ap); |
| + |
| + net::HttpRequestHeaders fetch_headers; |
| + fetcher->GetExtraRequestHeaders(&fetch_headers); |
| + EXPECT_TRUE(fetch_headers.HasHeader( |
| + ExtensionDownloader::kUpdateInteractivityHeader)); |
| + EXPECT_TRUE( |
| + fetch_headers.HasHeader(ExtensionDownloader::kUpdateAppIdHeader)); |
| + EXPECT_TRUE( |
| + fetch_headers.HasHeader(ExtensionDownloader::kUpdateUpdaterHeader)); |
| + |
| + std::string interactivity_value; |
| + fetch_headers.GetHeader(ExtensionDownloader::kUpdateInteractivityHeader, |
| + &interactivity_value); |
| + EXPECT_EQ(foreground_check ? "fg" : "bg", interactivity_value); |
|
Devlin
2017/03/24 15:14:46
nit: Why not use the ExtensionDownloader constants
Minh X. Nguyen
2017/03/27 23:05:29
This is to make sure that any change in these cons
|
| + |
| + std::string appid_value; |
| + fetch_headers.GetHeader(ExtensionDownloader::kUpdateAppIdHeader, |
| + &appid_value); |
| + EXPECT_EQ(extensions[0]->id(), appid_value); |
|
Devlin
2017/03/24 15:14:46
Can we add a test for multiple extension ids?
Minh X. Nguyen
2017/03/27 23:05:29
Done.
|
| + |
| + std::string updater_value; |
| + fetch_headers.GetHeader(ExtensionDownloader::kUpdateUpdaterHeader, |
| + &updater_value); |
| + std::string expected_updater_value = base::StringPrintf( |
| + "%s-%s", UpdateQueryParams::GetProdIdString(UpdateQueryParams::CRX), |
| + UpdateQueryParams::GetProdVersion().c_str()); |
| + EXPECT_EQ(expected_updater_value, updater_value); |
| } |
| void TestInstallSource() { |
| @@ -845,7 +873,7 @@ class ExtensionUpdaterTest : public testing::Test { |
| std::unique_ptr<ManifestFetchData> fetch_data( |
| CreateManifestFetchData(GURL("http://localhost/foo"))); |
| fetch_data->AddExtension(id, version, &kNeverPingedData, |
| - kEmptyUpdateUrlData, install_source); |
| + kEmptyUpdateUrlData, install_source, false); |
| std::map<std::string, std::string> params; |
| VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); |
| EXPECT_EQ(id, params["id"]); |
| @@ -872,10 +900,10 @@ class ExtensionUpdaterTest : public testing::Test { |
| const std::string id1 = crx_file::id_util::GenerateId("1"); |
| const std::string id2 = crx_file::id_util::GenerateId("2"); |
| fetch_data->AddExtension(id1, "1.0.0.0", &kNeverPingedData, |
| - kEmptyUpdateUrlData, std::string()); |
| + kEmptyUpdateUrlData, std::string(), false); |
| AddParseResult(id1, "1.1", "http://localhost/e1_1.1.crx", &updates); |
| fetch_data->AddExtension(id2, "2.0.0.0", &kNeverPingedData, |
| - kEmptyUpdateUrlData, std::string()); |
| + kEmptyUpdateUrlData, std::string(), false); |
| AddParseResult(id2, "2.0.0.0", "http://localhost/e2_2.0.crx", &updates); |
| EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(false)); |
| @@ -914,7 +942,7 @@ class ExtensionUpdaterTest : public testing::Test { |
| for (it = ids_for_update_check.begin(); |
| it != ids_for_update_check.end(); ++it) { |
| fetch_data->AddExtension(*it, "1.0.0.0", &kNeverPingedData, |
| - kEmptyUpdateUrlData, std::string()); |
| + kEmptyUpdateUrlData, std::string(), false); |
| AddParseResult(*it, "1.1", "http://localhost/e1_1.1.crx", &updates); |
| } |
| @@ -952,13 +980,13 @@ class ExtensionUpdaterTest : public testing::Test { |
| CreateManifestFetchData(kUpdateUrl)); |
| ManifestFetchData::PingData zeroDays(0, 0, true, 0); |
| fetch1->AddExtension("1111", "1.0", &zeroDays, kEmptyUpdateUrlData, |
| - std::string()); |
| + std::string(), false); |
| fetch2->AddExtension("2222", "2.0", &zeroDays, kEmptyUpdateUrlData, |
| - std::string()); |
| + std::string(), false); |
| fetch3->AddExtension("3333", "3.0", &zeroDays, kEmptyUpdateUrlData, |
| - std::string()); |
| + std::string(), false); |
| fetch4->AddExtension("4444", "4.0", &zeroDays, kEmptyUpdateUrlData, |
| - std::string()); |
| + std::string(), false); |
| // This will start the first fetcher and queue the others. The next in queue |
| // is started as each fetcher receives its response. Note that the fetchers |
| @@ -1090,7 +1118,7 @@ class ExtensionUpdaterTest : public testing::Test { |
| CreateManifestFetchData(kUpdateUrl)); |
| ManifestFetchData::PingData zeroDays(0, 0, true, 0); |
| fetch->AddExtension("1111", "1.0", &zeroDays, kEmptyUpdateUrlData, |
| - std::string()); |
| + std::string(), false); |
| // This will start the first fetcher. |
| downloader.StartUpdateCheck(std::move(fetch)); |
| @@ -1118,7 +1146,7 @@ class ExtensionUpdaterTest : public testing::Test { |
| // should not retry. |
| fetch.reset(CreateManifestFetchData(kUpdateUrl)); |
| fetch->AddExtension("1111", "1.0", &zeroDays, kEmptyUpdateUrlData, |
| - std::string()); |
| + std::string(), false); |
| // This will start the first fetcher. |
| downloader.StartUpdateCheck(std::move(fetch)); |
| @@ -1780,7 +1808,7 @@ class ExtensionUpdaterTest : public testing::Test { |
| const Extension* extension = tmp[0].get(); |
| fetch_data->AddExtension(extension->id(), extension->VersionString(), |
| &kNeverPingedData, kEmptyUpdateUrlData, |
| - std::string()); |
| + std::string(), false); |
| UpdateManifest::Results results; |
| results.daystart_elapsed_seconds = 750; |
| @@ -1893,7 +1921,7 @@ class ExtensionUpdaterTest : public testing::Test { |
| ManifestFetchData* CreateManifestFetchData(const GURL& update_url) { |
| return new ManifestFetchData(update_url, 0, "", |
| UpdateQueryParams::Get(UpdateQueryParams::CRX), |
| - ManifestFetchData::PING); |
| + ManifestFetchData::PING, false); |
| } |
| private: |
| @@ -1924,8 +1952,10 @@ TEST_F(ExtensionUpdaterTest, TestUpdateUrlData) { |
| TestUpdateUrlDataEmpty(); |
| TestUpdateUrlDataSimple(); |
| TestUpdateUrlDataCompound(); |
| - TestUpdateUrlDataFromGallery( |
| - extension_urls::GetWebstoreUpdateUrl().spec()); |
| + TestUpdateUrlDataFromGallery(extension_urls::GetWebstoreUpdateUrl().spec(), |
| + false); |
| + TestUpdateUrlDataFromGallery(extension_urls::GetWebstoreUpdateUrl().spec(), |
| + true); |
| } |
| TEST_F(ExtensionUpdaterTest, TestInstallSource) { |
| @@ -2133,7 +2163,7 @@ TEST_F(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) { |
| std::string id = crx_file::id_util::GenerateId("foo"); |
| EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false)); |
| EXPECT_TRUE(downloader->AddPendingExtension( |
| - id, GURL("http://example.com/update"), false, 0)); |
| + id, GURL("http://example.com/update"), false, 0, false)); |
| downloader->StartAllPending(NULL); |
| Mock::VerifyAndClearExpectations(&delegate); |
| EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); |
| @@ -2141,13 +2171,13 @@ TEST_F(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) { |
| // Extensions with invalid update URLs should be rejected. |
| id = crx_file::id_util::GenerateId("foo2"); |
| EXPECT_FALSE(downloader->AddPendingExtension(id, GURL("http:google.com:foo"), |
| - false, 0)); |
| + false, 0, false)); |
| downloader->StartAllPending(NULL); |
| EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); |
| // Extensions with empty IDs should be rejected. |
| EXPECT_FALSE( |
| - downloader->AddPendingExtension(std::string(), GURL(), false, 0)); |
| + downloader->AddPendingExtension(std::string(), GURL(), false, 0, false)); |
| downloader->StartAllPending(NULL); |
| EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); |
| @@ -2163,7 +2193,7 @@ TEST_F(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) { |
| // filled in. |
| id = crx_file::id_util::GenerateId("foo3"); |
| EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false)); |
| - EXPECT_TRUE(downloader->AddPendingExtension(id, GURL(), false, 0)); |
| + EXPECT_TRUE(downloader->AddPendingExtension(id, GURL(), false, 0, false)); |
| downloader->StartAllPending(NULL); |
| EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); |