-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementing 3 sample manual tests as interactive_uitest
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
Showing
9 changed files
with
428 additions
and
0 deletions.
There are no files selected for viewing
146 changes: 146 additions & 0 deletions
146
chrome/browser/ui/views/collected_cookies_view_interactive_uitest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.