Commit 9042e84e authored by Sophie Chang's avatar Sophie Chang Committed by Chromium LUCI CQ

Add initial browser tests for downloading models

Bug: 1146151
Change-Id: Ic327827d7c3fb65c1baaf92562320062372ca8cf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2573520Reviewed-by: default avatarFilip Gorski <fgorski@chromium.org>
Reviewed-by: default avatarMichael Crouse <mcrouse@chromium.org>
Commit-Queue: Sophie Chang <sophiechang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833740}
parent 51e3825a
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "components/download/public/background_service/download_service.h" #include "components/download/public/background_service/download_service.h"
#include "components/optimization_guide/optimization_guide_enums.h" #include "components/optimization_guide/optimization_guide_enums.h"
#include "components/optimization_guide/optimization_guide_features.h" #include "components/optimization_guide/optimization_guide_features.h"
#include "components/optimization_guide/optimization_guide_switches.h"
#include "components/optimization_guide/optimization_guide_util.h" #include "components/optimization_guide/optimization_guide_util.h"
#include "components/services/unzip/content/unzip_service.h" #include "components/services/unzip/content/unzip_service.h"
#include "components/services/unzip/public/cpp/unzip.h" #include "components/services/unzip/public/cpp/unzip.h"
...@@ -214,7 +215,7 @@ PredictionModelDownloadManager::ProcessDownload( ...@@ -214,7 +215,7 @@ PredictionModelDownloadManager::ProcessDownload(
const base::FilePath& file_path) { const base::FilePath& file_path) {
DCHECK(background_task_runner_->RunsTasksInCurrentSequence()); DCHECK(background_task_runner_->RunsTasksInCurrentSequence());
if (should_verify_download_) { if (!switches::ShouldSkipModelDownloadVerificationForTesting()) {
// Verify that the |file_path| contains a file signed with a key we trust. // Verify that the |file_path| contains a file signed with a key we trust.
crx_file::VerifierResult verifier_result = crx_file::Verify( crx_file::VerifierResult verifier_result = crx_file::Verify(
file_path, crx_file::VerifierFormat::CRX3_WITH_PUBLISHER_PROOF, file_path, crx_file::VerifierFormat::CRX3_WITH_PUBLISHER_PROOF,
...@@ -269,7 +270,7 @@ void PredictionModelDownloadManager::OnDownloadUnzipped( ...@@ -269,7 +270,7 @@ void PredictionModelDownloadManager::OnDownloadUnzipped(
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// Clean up original download file when this function finishes. // Clean up original download file when this function finishes.
base::SequencedTaskRunnerHandle::Get()->PostTask( background_task_runner_->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(base::GetDeleteFileCallback(), original_file_path)); base::BindOnce(base::GetDeleteFileCallback(), original_file_path));
...@@ -351,8 +352,4 @@ void PredictionModelDownloadManager::NotifyModelReady( ...@@ -351,8 +352,4 @@ void PredictionModelDownloadManager::NotifyModelReady(
observer.OnModelReady(*model); observer.OnModelReady(*model);
} }
void PredictionModelDownloadManager::TurnOffVerificationForTesting() {
should_verify_download_ = false;
}
} // namespace optimization_guide } // namespace optimization_guide
...@@ -116,9 +116,6 @@ class PredictionModelDownloadManager { ...@@ -116,9 +116,6 @@ class PredictionModelDownloadManager {
// Must be invoked on the UI thread. // Must be invoked on the UI thread.
void NotifyModelReady(const base::Optional<proto::PredictionModel>& model); void NotifyModelReady(const base::Optional<proto::PredictionModel>& model);
// Turns off CRX3 verification for testing.
void TurnOffVerificationForTesting();
// The set of GUIDs that are still pending download. // The set of GUIDs that are still pending download.
std::set<std::string> pending_download_guids_; std::set<std::string> pending_download_guids_;
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "components/download/public/background_service/test/mock_download_service.h" #include "components/download/public/background_service/test/mock_download_service.h"
#include "components/optimization_guide/optimization_guide_enums.h" #include "components/optimization_guide/optimization_guide_enums.h"
#include "components/optimization_guide/optimization_guide_features.h" #include "components/optimization_guide/optimization_guide_features.h"
#include "components/optimization_guide/optimization_guide_switches.h"
#include "components/optimization_guide/optimization_guide_util.h" #include "components/optimization_guide/optimization_guide_util.h"
#include "components/services/unzip/content/unzip_service.h" #include "components/services/unzip/content/unzip_service.h"
#include "components/services/unzip/in_process_unzipper.h" #include "components/services/unzip/in_process_unzipper.h"
...@@ -158,7 +159,8 @@ class PredictionModelDownloadManagerTest ...@@ -158,7 +159,8 @@ class PredictionModelDownloadManagerTest
} }
void TurnOffDownloadVerification() { void TurnOffDownloadVerification() {
download_manager_->TurnOffVerificationForTesting(); base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kDisableModelDownloadVerificationForTesting);
} }
private: private:
......
...@@ -565,6 +565,7 @@ bool PathProvider(int key, base::FilePath* result) { ...@@ -565,6 +565,7 @@ bool PathProvider(int key, base::FilePath* result) {
if (!base::PathService::Get(chrome::DIR_USER_DATA, &cur)) if (!base::PathService::Get(chrome::DIR_USER_DATA, &cur))
return false; return false;
cur = cur.Append(FILE_PATH_LITERAL("OptimizationGuidePredictionModels")); cur = cur.Append(FILE_PATH_LITERAL("OptimizationGuidePredictionModels"));
create_dir = true;
break; break;
default: default:
......
...@@ -66,6 +66,9 @@ const char kDisableFetchingHintsAtNavigationStartForTesting[] = ...@@ -66,6 +66,9 @@ const char kDisableFetchingHintsAtNavigationStartForTesting[] =
const char kDisableCheckingUserPermissionsForTesting[] = const char kDisableCheckingUserPermissionsForTesting[] =
"disable-checking-optimization-guide-user-permissions"; "disable-checking-optimization-guide-user-permissions";
const char kDisableModelDownloadVerificationForTesting[] =
"disable-model-download-verification";
bool IsHintComponentProcessingDisabled() { bool IsHintComponentProcessingDisabled() {
return base::CommandLine::ForCurrentProcess()->HasSwitch(kHintsProtoOverride); return base::CommandLine::ForCurrentProcess()->HasSwitch(kHintsProtoOverride);
} }
...@@ -149,5 +152,10 @@ bool ShouldOverrideCheckingUserPermissionsToFetchHintsForTesting() { ...@@ -149,5 +152,10 @@ bool ShouldOverrideCheckingUserPermissionsToFetchHintsForTesting() {
return command_line->HasSwitch(kDisableCheckingUserPermissionsForTesting); return command_line->HasSwitch(kDisableCheckingUserPermissionsForTesting);
} }
bool ShouldSkipModelDownloadVerificationForTesting() {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
return command_line->HasSwitch(kDisableModelDownloadVerificationForTesting);
}
} // namespace switches } // namespace switches
} // namespace optimization_guide } // namespace optimization_guide
...@@ -29,6 +29,7 @@ extern const char kPurgeHintsStore[]; ...@@ -29,6 +29,7 @@ extern const char kPurgeHintsStore[];
extern const char kPurgeModelAndFeaturesStore[]; extern const char kPurgeModelAndFeaturesStore[];
extern const char kDisableFetchingHintsAtNavigationStartForTesting[]; extern const char kDisableFetchingHintsAtNavigationStartForTesting[];
extern const char kDisableCheckingUserPermissionsForTesting[]; extern const char kDisableCheckingUserPermissionsForTesting[];
extern const char kDisableModelDownloadVerificationForTesting[];
// Returns whether the hint component should be processed. // Returns whether the hint component should be processed.
// Available hint components are only processed if a proto override isn't being // Available hint components are only processed if a proto override isn't being
...@@ -72,6 +73,9 @@ bool DisableFetchingHintsAtNavigationStartForTesting(); ...@@ -72,6 +73,9 @@ bool DisableFetchingHintsAtNavigationStartForTesting();
// tests. // tests.
bool ShouldOverrideCheckingUserPermissionsToFetchHintsForTesting(); bool ShouldOverrideCheckingUserPermissionsToFetchHintsForTesting();
// Returns true if the verification of model downloads should be skipped.
bool ShouldSkipModelDownloadVerificationForTesting();
} // namespace switches } // namespace switches
} // namespace optimization_guide } // namespace optimization_guide
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment