| Index: chrome/browser/budget_service/budget_manager_browsertest.cc
|
| diff --git a/chrome/browser/budget_service/budget_manager_browsertest.cc b/chrome/browser/budget_service/budget_manager_browsertest.cc
|
| index 65e56f76bb06e1235964fb79ceb9290a577f042b..954e4d599de137c8b1d0de6e266364a22eb4505c 100644
|
| --- a/chrome/browser/budget_service/budget_manager_browsertest.cc
|
| +++ b/chrome/browser/budget_service/budget_manager_browsertest.cc
|
| @@ -8,12 +8,16 @@
|
| #include "build/build_config.h"
|
| #include "chrome/browser/budget_service/budget_manager.h"
|
| #include "chrome/browser/budget_service/budget_manager_factory.h"
|
| +#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
|
| +#include "chrome/browser/engagement/site_engagement_score.h"
|
| #include "chrome/browser/engagement/site_engagement_service.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| #include "chrome/browser/ui/browser.h"
|
| #include "chrome/browser/ui/tabs/tab_strip_model.h"
|
| #include "chrome/test/base/in_process_browser_test.h"
|
| #include "chrome/test/base/ui_test_utils.h"
|
| +#include "components/content_settings/core/browser/host_content_settings_map.h"
|
| +#include "components/content_settings/core/common/content_settings_types.h"
|
| #include "content/public/browser/browser_context.h"
|
| #include "content/public/browser/web_contents.h"
|
| #include "content/public/common/content_switches.h"
|
| @@ -44,6 +48,15 @@ class BudgetManagerBrowserTest : public InProcessBrowserTest {
|
|
|
| // InProcessBrowserTest:
|
| void SetUpOnMainThread() override {
|
| + SiteEngagementScore::SetParamValuesForTesting();
|
| +
|
| + // Grant Notification permission for these tests. See the privacy
|
| + // requirement for this outlined in https://crbug.com/710809.
|
| + HostContentSettingsMapFactory::GetForProfile(browser()->profile())
|
| + ->SetContentSettingDefaultScope(https_server_->base_url(), GURL(),
|
| + CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
|
| + std::string(), CONTENT_SETTING_ALLOW);
|
| +
|
| LoadTestPage();
|
| InProcessBrowserTest::SetUpOnMainThread();
|
| budget_manager_ = BudgetManagerFactory::GetForProfile(browser()->profile());
|
| @@ -57,10 +70,21 @@ class BudgetManagerBrowserTest : public InProcessBrowserTest {
|
| InProcessBrowserTest::SetUpCommandLine(command_line);
|
| }
|
|
|
| + // Sets the absolute Site Engagement |score| for the testing origin, assuming
|
| + // that notification permission has been granted.
|
| + // The |score| must be higher than the bonus points awarded to an origin for
|
| + // having the Notification permission granted. Should be wrapped in the
|
| + // ASSERT_NO_FATAL_FAILURE macro because it contains an ASSERT_GE.
|
| void SetSiteEngagementScore(double score) {
|
| SiteEngagementService* service =
|
| SiteEngagementService::Get(browser()->profile());
|
| - service->ResetBaseScoreForURL(https_server_->GetURL(kTestURL), score);
|
| +
|
| + double notification_permission_bonus =
|
| + SiteEngagementScore::GetNotificationPermissionPoints();
|
| + ASSERT_GE(score, notification_permission_bonus);
|
| +
|
| + service->ResetBaseScoreForURL(https_server_->GetURL(kTestURL),
|
| + score - notification_permission_bonus);
|
| }
|
|
|
| bool RunScript(const std::string& script, std::string* result) {
|
| @@ -102,7 +126,7 @@ class BudgetManagerBrowserTest : public InProcessBrowserTest {
|
| IN_PROC_BROWSER_TEST_F(BudgetManagerBrowserTest, BudgetInDocument) {
|
| std::string script_result;
|
|
|
| - SetSiteEngagementScore(5);
|
| + ASSERT_NO_FATAL_FAILURE(SetSiteEngagementScore(5));
|
|
|
| // Site Engagement score of 5 gives a budget of 2.
|
| ASSERT_TRUE(RunScript("documentGetBudget()", &script_result));
|
| @@ -135,7 +159,7 @@ IN_PROC_BROWSER_TEST_F(BudgetManagerBrowserTest, BudgetInWorker) {
|
| ASSERT_EQ("ok - service worker registered", script_result);
|
|
|
| LoadTestPage(); // Reload to become controlled.
|
| - SetSiteEngagementScore(12);
|
| + ASSERT_NO_FATAL_FAILURE(SetSiteEngagementScore(12));
|
|
|
| ASSERT_TRUE(RunScript("isControlled()", &script_result));
|
| ASSERT_EQ("true - is controlled", script_result);
|
|
|