|
14 | 14 | #include "chrome/test/base/ui_test_utils.h"
|
15 | 15 | #include "components/network_session_configurator/common/network_switches.h"
|
16 | 16 | #include "components/url_formatter/url_formatter.h"
|
| 17 | +#include "components/variations/active_field_trials.h" |
| 18 | +#include "components/variations/metrics_util.h" |
17 | 19 | #include "content/public/browser/navigation_entry.h"
|
18 | 20 | #include "content/public/browser/navigation_handle.h"
|
19 | 21 | #include "content/public/browser/notification_service.h"
|
@@ -447,8 +449,12 @@ class SignInIsolationBrowserTest : public ChromeNavigationBrowserTest {
|
447 | 449 | : https_server_(net::EmbeddedTestServer::TYPE_HTTPS) {}
|
448 | 450 | ~SignInIsolationBrowserTest() override {}
|
449 | 451 |
|
450 |
| - void SetUp() override { |
| 452 | + virtual void InitFeatureList() { |
451 | 453 | feature_list_.InitAndEnableFeature(features::kSignInProcessIsolation);
|
| 454 | + } |
| 455 | + |
| 456 | + void SetUp() override { |
| 457 | + InitFeatureList(); |
452 | 458 | https_server_.ServeFilesFromSourceDirectory("chrome/test/data");
|
453 | 459 | ASSERT_TRUE(https_server_.InitializeAndListen());
|
454 | 460 | ChromeNavigationBrowserTest::SetUp();
|
@@ -477,8 +483,41 @@ class SignInIsolationBrowserTest : public ChromeNavigationBrowserTest {
|
477 | 483 |
|
478 | 484 | net::EmbeddedTestServer* https_server() { return &https_server_; }
|
479 | 485 |
|
480 |
| - private: |
| 486 | + bool HasSyntheticTrial(const std::string& trial_name) { |
| 487 | + std::vector<std::string> synthetic_trials; |
| 488 | + variations::GetSyntheticTrialGroupIdsAsString(&synthetic_trials); |
| 489 | + std::string trial_hash = |
| 490 | + base::StringPrintf("%x", metrics::HashName(trial_name)); |
| 491 | + |
| 492 | + for (auto entry : synthetic_trials) { |
| 493 | + if (base::StartsWith(entry, trial_hash, base::CompareCase::SENSITIVE)) |
| 494 | + return true; |
| 495 | + } |
| 496 | + |
| 497 | + return false; |
| 498 | + } |
| 499 | + |
| 500 | + bool IsInSyntheticTrialGroup(const std::string& trial_name, |
| 501 | + const std::string& trial_group) { |
| 502 | + std::vector<std::string> synthetic_trials; |
| 503 | + variations::GetSyntheticTrialGroupIdsAsString(&synthetic_trials); |
| 504 | + std::string expected_entry = base::StringPrintf( |
| 505 | + "%x-%x", metrics::HashName(trial_name), metrics::HashName(trial_group)); |
| 506 | + |
| 507 | + for (auto entry : synthetic_trials) { |
| 508 | + if (entry == expected_entry) |
| 509 | + return true; |
| 510 | + } |
| 511 | + |
| 512 | + return false; |
| 513 | + } |
| 514 | + |
| 515 | + const std::string kSyntheticTrialName = "SignInProcessIsolationActive"; |
| 516 | + |
| 517 | + protected: |
481 | 518 | base::test::ScopedFeatureList feature_list_;
|
| 519 | + |
| 520 | + private: |
482 | 521 | net::EmbeddedTestServer https_server_;
|
483 | 522 |
|
484 | 523 | DISALLOW_COPY_AND_ASSIGN(SignInIsolationBrowserTest);
|
@@ -507,3 +546,136 @@ IN_PROC_BROWSER_TEST_F(SignInIsolationBrowserTest, NavigateToSignInPage) {
|
507 | 546 | manager.WaitForNavigationFinished();
|
508 | 547 | EXPECT_NE(web_contents->GetMainFrame()->GetSiteInstance(), first_instance);
|
509 | 548 | }
|
| 549 | + |
| 550 | +// The next four tests verify that the synthetic field trial is set correctly |
| 551 | +// for sign-in process isolation. The synthetic field trial should be created |
| 552 | +// when browsing to the sign-in URL for the first time, and it should reflect |
| 553 | +// whether or not the sign-in isolation base::Feature is enabled, and whether |
| 554 | +// or not it is force-enabled from the command line. |
| 555 | +IN_PROC_BROWSER_TEST_F(SignInIsolationBrowserTest, SyntheticTrial) { |
| 556 | + EXPECT_FALSE(HasSyntheticTrial(kSyntheticTrialName)); |
| 557 | + |
| 558 | + ui_test_utils::NavigateToURL( |
| 559 | + browser(), https_server()->GetURL("foo.com", "/title1.html")); |
| 560 | + EXPECT_FALSE(HasSyntheticTrial(kSyntheticTrialName)); |
| 561 | + |
| 562 | + GURL signin_url( |
| 563 | + https_server()->GetURL("accounts.google.com", "/title1.html")); |
| 564 | + |
| 565 | + // This test class uses InitAndEnableFeature, which overrides the feature |
| 566 | + // settings as if it came from the command line, so by default, browsing to |
| 567 | + // the sign-in URL should create the synthetic trial with ForceEnabled. |
| 568 | + ui_test_utils::NavigateToURL(browser(), signin_url); |
| 569 | + EXPECT_TRUE(IsInSyntheticTrialGroup(kSyntheticTrialName, "ForceEnabled")); |
| 570 | +} |
| 571 | + |
| 572 | +// This test class is used to check the synthetic sign-in trial for the Enabled |
| 573 | +// group. It creates a new field trial (with 100% probability of being in the |
| 574 | +// group), and initializes the test class's ScopedFeatureList using it, being |
| 575 | +// careful to not override it using the command line (which corresponds to |
| 576 | +// ForceEnabled). |
| 577 | +class EnabledSignInIsolationBrowserTest : public SignInIsolationBrowserTest { |
| 578 | + public: |
| 579 | + EnabledSignInIsolationBrowserTest() {} |
| 580 | + ~EnabledSignInIsolationBrowserTest() override {} |
| 581 | + |
| 582 | + void InitFeatureList() override {} |
| 583 | + |
| 584 | + void SetUpOnMainThread() override { |
| 585 | + const std::string kTrialName = "SignInProcessIsolation"; |
| 586 | + const std::string kGroupName = "FooGroup"; // unused |
| 587 | + scoped_refptr<base::FieldTrial> trial = |
| 588 | + base::FieldTrialList::CreateFieldTrial(kTrialName, kGroupName); |
| 589 | + |
| 590 | + std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 591 | + feature_list->RegisterFieldTrialOverride( |
| 592 | + features::kSignInProcessIsolation.name, |
| 593 | + base::FeatureList::OverrideState::OVERRIDE_ENABLE_FEATURE, trial.get()); |
| 594 | + |
| 595 | + feature_list_.InitWithFeatureList(std::move(feature_list)); |
| 596 | + SignInIsolationBrowserTest::SetUpOnMainThread(); |
| 597 | + } |
| 598 | + |
| 599 | + DISALLOW_COPY_AND_ASSIGN(EnabledSignInIsolationBrowserTest); |
| 600 | +}; |
| 601 | + |
| 602 | +IN_PROC_BROWSER_TEST_F(EnabledSignInIsolationBrowserTest, SyntheticTrial) { |
| 603 | + EXPECT_FALSE(HasSyntheticTrial(kSyntheticTrialName)); |
| 604 | + EXPECT_FALSE(IsInSyntheticTrialGroup(kSyntheticTrialName, "Enabled")); |
| 605 | + |
| 606 | + GURL signin_url = |
| 607 | + https_server()->GetURL("accounts.google.com", "/title1.html"); |
| 608 | + ui_test_utils::NavigateToURL(browser(), signin_url); |
| 609 | + EXPECT_TRUE(IsInSyntheticTrialGroup(kSyntheticTrialName, "Enabled")); |
| 610 | + |
| 611 | + // A repeat navigation shouldn't change the synthetic trial. |
| 612 | + ui_test_utils::NavigateToURL( |
| 613 | + browser(), https_server()->GetURL("accounts.google.com", "/title2.html")); |
| 614 | + EXPECT_TRUE(IsInSyntheticTrialGroup(kSyntheticTrialName, "Enabled")); |
| 615 | +} |
| 616 | + |
| 617 | +// This test class is similar to EnabledSignInIsolationBrowserTest, but for the |
| 618 | +// Disabled group of the synthetic sign-in trial. |
| 619 | +class DisabledSignInIsolationBrowserTest : public SignInIsolationBrowserTest { |
| 620 | + public: |
| 621 | + DisabledSignInIsolationBrowserTest() {} |
| 622 | + ~DisabledSignInIsolationBrowserTest() override {} |
| 623 | + |
| 624 | + void InitFeatureList() override {} |
| 625 | + |
| 626 | + void SetUpOnMainThread() override { |
| 627 | + const std::string kTrialName = "SignInProcessIsolation"; |
| 628 | + const std::string kGroupName = "FooGroup"; // unused |
| 629 | + scoped_refptr<base::FieldTrial> trial = |
| 630 | + base::FieldTrialList::CreateFieldTrial(kTrialName, kGroupName); |
| 631 | + |
| 632 | + std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 633 | + feature_list->RegisterFieldTrialOverride( |
| 634 | + features::kSignInProcessIsolation.name, |
| 635 | + base::FeatureList::OverrideState::OVERRIDE_DISABLE_FEATURE, |
| 636 | + trial.get()); |
| 637 | + |
| 638 | + feature_list_.InitWithFeatureList(std::move(feature_list)); |
| 639 | + SignInIsolationBrowserTest::SetUpOnMainThread(); |
| 640 | + } |
| 641 | + |
| 642 | + DISALLOW_COPY_AND_ASSIGN(DisabledSignInIsolationBrowserTest); |
| 643 | +}; |
| 644 | + |
| 645 | +IN_PROC_BROWSER_TEST_F(DisabledSignInIsolationBrowserTest, SyntheticTrial) { |
| 646 | + EXPECT_FALSE(IsInSyntheticTrialGroup(kSyntheticTrialName, "Disabled")); |
| 647 | + GURL signin_url = |
| 648 | + https_server()->GetURL("accounts.google.com", "/title1.html"); |
| 649 | + ui_test_utils::NavigateToURL(browser(), signin_url); |
| 650 | + EXPECT_TRUE(IsInSyntheticTrialGroup(kSyntheticTrialName, "Disabled")); |
| 651 | +} |
| 652 | + |
| 653 | +// This test class is similar to EnabledSignInIsolationBrowserTest, but for the |
| 654 | +// ForceDisabled group of the synthetic sign-in trial. |
| 655 | +class ForceDisabledSignInIsolationBrowserTest |
| 656 | + : public SignInIsolationBrowserTest { |
| 657 | + public: |
| 658 | + ForceDisabledSignInIsolationBrowserTest() {} |
| 659 | + ~ForceDisabledSignInIsolationBrowserTest() override {} |
| 660 | + |
| 661 | + void InitFeatureList() override { |
| 662 | + feature_list_.InitAndDisableFeature(features::kSignInProcessIsolation); |
| 663 | + } |
| 664 | + |
| 665 | + DISALLOW_COPY_AND_ASSIGN(ForceDisabledSignInIsolationBrowserTest); |
| 666 | +}; |
| 667 | + |
| 668 | +IN_PROC_BROWSER_TEST_F(ForceDisabledSignInIsolationBrowserTest, |
| 669 | + SyntheticTrial) { |
| 670 | + // Test subframe navigation in this case, since that should also trigger |
| 671 | + // synthetic trial creation. |
| 672 | + ui_test_utils::NavigateToURL(browser(), |
| 673 | + https_server()->GetURL("a.com", "/iframe.html")); |
| 674 | + content::WebContents* web_contents = |
| 675 | + browser()->tab_strip_model()->GetActiveWebContents(); |
| 676 | + EXPECT_FALSE(IsInSyntheticTrialGroup(kSyntheticTrialName, "ForceDisabled")); |
| 677 | + GURL signin_url = |
| 678 | + https_server()->GetURL("accounts.google.com", "/title1.html"); |
| 679 | + EXPECT_TRUE(NavigateIframeToURL(web_contents, "test", signin_url)); |
| 680 | + EXPECT_TRUE(IsInSyntheticTrialGroup(kSyntheticTrialName, "ForceDisabled")); |
| 681 | +} |
0 commit comments