Skip to content

Commit

Permalink
Implementing 3 sample manual tests as interactive_uitest
Browse files Browse the repository at this point in the history
This CL implemented following manual test cases with the interactive sequence as a demonstration to convert manual tests as interactive ui tests:
http://testtracker/efforts/testcase/detail/214406727
http://testtracker/efforts/testcase/detail/214406570
http://testtracker/efforts/testcase/detail/214404057

Bug: 1309204
Change-Id: Ic1ef3da8078a5f6bf09b13b8315844a6f21044b0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3573063
Commit-Queue: Kuan Huang <kuanhuang@chromium.org>
Reviewed-by: Dana Fried <dfried@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1002814}
  • Loading branch information
Kuan Huang authored and Chromium LUCI CQ committed May 12, 2022
1 parent 4875911 commit 4bbf05e
Show file tree
Hide file tree
Showing 9 changed files with 428 additions and 0 deletions.
146 changes: 146 additions & 0 deletions chrome/browser/ui/views/collected_cookies_view_interactive_uitest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
// Copyright 2022 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/test/bind.h"
#include "chrome/browser/browsing_data/cookies_tree_model.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_element_identifiers.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/views/collected_cookies_views.h"
#include "chrome/browser/ui/views/page_info/page_info_main_view.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/interaction/interaction_sequence_browser_util.h"
#include "content/public/test/browser_test.h"
#include "net/dns/mock_host_resolver.h"
#include "ui/base/interaction/expect_call_in_scope.h"
#include "ui/base/interaction/interaction_sequence.h"
#include "ui/base/interaction/interaction_test_util.h"
#include "ui/views/controls/tabbed_pane/tabbed_pane.h"
#include "ui/views/controls/tree/tree_view.h"
#include "ui/views/interaction/element_tracker_views.h"
#include "ui/views/interaction/interaction_test_util_views.h"
#include "ui/views/view_utils.h"

#if BUILDFLAG(IS_MAC)
#include "ui/base/interaction/interaction_test_util_mac.h"
#endif

namespace {
DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE(kInteractionSequenceBrowserUtilTestId);
} // namespace

class CollectedCookiesViewInteractiveUiTest : public InProcessBrowserTest {
public:
CollectedCookiesViewInteractiveUiTest() = default;
~CollectedCookiesViewInteractiveUiTest() override = default;
CollectedCookiesViewInteractiveUiTest(
const CollectedCookiesViewInteractiveUiTest&) = delete;
void operator=(const CollectedCookiesViewInteractiveUiTest&) = delete;

void SetUp() override {
set_open_about_blank_on_browser_launch(true);
ASSERT_TRUE(embedded_test_server()->InitializeAndListen());
test_util_.AddSimulator(
std::make_unique<views::test::InteractionTestUtilSimulatorViews>());
#if BUILDFLAG(IS_MAC)
test_util_.AddSimulator(
std::make_unique<ui::test::InteractionTestUtilSimulatorMac>());
#endif
InProcessBrowserTest::SetUp();
}

void SetUpOnMainThread() override {
InProcessBrowserTest::SetUpOnMainThread();
host_resolver()->AddRule("*", "127.0.0.1");
content::SetupCrossSiteRedirector(embedded_test_server());
embedded_test_server()->StartAcceptingConnections();
}

void TearDownOnMainThread() override {
EXPECT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete());
InProcessBrowserTest::TearDownOnMainThread();
}

// Helper function that wait for element to show and click on it.
// This function will be implemented by a test util framework later.
auto Click(ui::ElementIdentifier element_id) {
return ui::InteractionSequence::StepBuilder()
.SetElementID(element_id)
.SetMustRemainVisible(false)
.SetStartCallback(base::BindLambdaForTesting(
[&](ui::InteractionSequence*, ui::TrackedElement* element) {
test_util_.PressButton(element);
}))
.Build();
}

ui::test::InteractionTestUtil test_util_;
};

IN_PROC_BROWSER_TEST_F(CollectedCookiesViewInteractiveUiTest,
CheckCookiesAreBlockedInIncognitoWindow) {
UNCALLED_MOCK_CALLBACK(ui::InteractionSequence::CompletedCallback, completed);
UNCALLED_MOCK_CALLBACK(ui::InteractionSequence::AbortedCallback, aborted);

const GURL third_party_cookie_page_url =
embedded_test_server()->GetURL("a.com", "/third_party_cookie.html");

Browser* browser = CreateIncognitoBrowser();

auto util = InteractionSequenceBrowserUtil::ForExistingTabInBrowser(
browser, kInteractionSequenceBrowserUtilTestId);
util->LoadPage(third_party_cookie_page_url);

auto sequence =
ui::InteractionSequence::Builder()
.SetCompletedCallback(completed.Get())
.SetAbortedCallback(aborted.Get())
.SetContext(browser->window()->GetElementContext())
// Wait for page loaded.
.AddStep(ui::InteractionSequence::StepBuilder()
.SetElementID(kInteractionSequenceBrowserUtilTestId)
.Build())
.AddStep(Click(kLocationIconElementId))
.AddStep(Click(PageInfoMainView::kCookieButtonElementId))
// Switch to Cookies in use - Blocked tab.
.AddStep(
ui::InteractionSequence::StepBuilder()
.SetElementID(CollectedCookiesViews::kTabbedPaneElementId)
.SetFindElementInAnyContext(true)
.SetStartCallback(base::BindLambdaForTesting(
[&](ui::InteractionSequence*,
ui::TrackedElement* element) {
// Tab on Blocked tab.
views::AsViewClass<views::TabbedPane>(
element->AsA<views::TrackedElementViews>()->view())
->SelectTabAt(1);
}))
.Build())
// Verify the blocked cookies.
.AddStep(ui::InteractionSequence::StepBuilder()
.SetElementID(
CollectedCookiesViews::kBlockedCookiesTreeElementId)
.SetFindElementInAnyContext(true)
.SetStartCallback(base::BindLambdaForTesting(
[&](ui::InteractionSequence*,
ui::TrackedElement* element) {
auto* blocked_cookies_tree =
views::AsViewClass<views::TreeView>(
element->AsA<views::TrackedElementViews>()
->view());
ASSERT_EQ(1, blocked_cookies_tree->GetRowCount());

auto* model = blocked_cookies_tree->model();
auto nodes = model->GetChildren(model->GetRoot());
ASSERT_EQ(1u, nodes.size());
ASSERT_EQ("http://b.com",
static_cast<CookieTreeNode*>(nodes[0])
->GetDetailedInfo()
.origin.Serialize());
}))
.Build())
.Build();

EXPECT_CALL_IN_SCOPE(completed, Run, sequence->RunSynchronouslyForTesting());
}
8 changes: 8 additions & 0 deletions chrome/browser/ui/views/collected_cookies_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
#include "ui/views/view_tracker.h"
#include "ui/views/widget/widget.h"

DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(CollectedCookiesViews,
kTabbedPaneElementId);
DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(CollectedCookiesViews,
kBlockedCookiesTreeElementId);

namespace {

// Dimensions of the tree views.
Expand Down Expand Up @@ -409,6 +414,7 @@ CollectedCookiesViews::CollectedCookiesViews(content::WebContents* web_contents)
tabbed_pane->AddTab(label_blocked, CreateBlockedPane());
tabbed_pane->SelectTabAt(0);
tabbed_pane->set_listener(this);
tabbed_pane->SetProperty(views::kElementIdentifierKey, kTabbedPaneElementId);

cookie_info_view_ = AddChildView(std::make_unique<CookieInfoView>());
// Fix the height of the cookie info view, which is scrollable. It needs to be
Expand Down Expand Up @@ -526,6 +532,8 @@ std::unique_ptr<views::View> CollectedCookiesViews::CreateBlockedPane() {
blocked_cookies_tree->SetEditable(false);
blocked_cookies_tree->set_auto_expand_children(true);
blocked_cookies_tree->SetController(this);
blocked_cookies_tree->SetProperty(views::kElementIdentifierKey,
kBlockedCookiesTreeElementId);
blocked_cookies_tree_ = blocked_cookies_tree.get();
auto* scroll_view =
pane->AddChildView(CreateScrollView(std::move(blocked_cookies_tree)));
Expand Down
4 changes: 4 additions & 0 deletions chrome/browser/ui/views/collected_cookies_views.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "base/memory/raw_ptr.h"
#include "components/content_settings/core/common/content_settings.h"
#include "ui/base/interaction/element_identifier.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/views/controls/tabbed_pane/tabbed_pane_listener.h"
#include "ui/views/controls/tree/tree_view_controller.h"
Expand Down Expand Up @@ -40,6 +41,9 @@ class CollectedCookiesViews : public views::DialogDelegateView,
public views::TreeViewController {
public:
METADATA_HEADER(CollectedCookiesViews);
DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kTabbedPaneElementId);
DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kBlockedCookiesTreeElementId);

CollectedCookiesViews(const CollectedCookiesViews&) = delete;
CollectedCookiesViews& operator=(const CollectedCookiesViews&) = delete;
~CollectedCookiesViews() override;
Expand Down
5 changes: 5 additions & 0 deletions chrome/browser/ui/views/page_info/page_info_main_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "ui/views/controls/separator.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/flex_layout.h"
#include "ui/views/view_class_properties.h"

#if BUILDFLAG(FULL_SAFE_BROWSING)
#include "chrome/browser/safe_browsing/chrome_password_protection_service.h"
Expand All @@ -51,6 +52,8 @@ constexpr float kMaxPermissionRowCount = 10.5;

} // namespace

DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(PageInfoMainView, kCookieButtonElementId);

PageInfoMainView::ContainerView::ContainerView() {
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical));
Expand Down Expand Up @@ -150,6 +153,8 @@ void PageInfoMainView::EnsureCookieInfo() {
PageInfoViewFactory::VIEW_ID_PAGE_INFO_LINK_OR_BUTTON_COOKIE_DIALOG,
tooltip, std::u16string(), PageInfoViewFactory::GetLaunchIcon())
.release();
cookie_button_->SetProperty(views::kElementIdentifierKey,
kCookieButtonElementId);
site_settings_view_->AddChildView(cookie_button_.get());

if (base::FeatureList::IsEnabled(
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/ui/views/page_info/page_info_main_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "components/page_info/core/proto/about_this_site_metadata.pb.h"
#include "components/page_info/page_info_ui.h"
#include "device/vr/buildflags/buildflags.h"
#include "ui/base/interaction/element_identifier.h"
#include "ui/views/view.h"

namespace views {
Expand Down Expand Up @@ -43,6 +44,7 @@ class PageInfoMainView : public views::View,
public:
// The width of the column size for permissions and chosen object icons.
static constexpr int kIconColumnWidth = 16;
DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kCookieButtonElementId);

// Container view that fills the bubble width for button rows. Supports
// updating the layout.
Expand Down

0 comments on commit 4bbf05e

Please sign in to comment.