Skip to content

Commit

Permalink
[Extensions c2s] Move methods to extensions toolbar ui test class
Browse files Browse the repository at this point in the history
Move menu page ui tests repeated method to toolbar ui test class.

Bug: none
Change-Id: I2c434a82a163781034868253303cdf2c74e24a6c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4336338
Commit-Queue: Emilia Paz <emiliapaz@chromium.org>
Reviewed-by: Kelvin Jiang <kelvinjiang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1122039}
  • Loading branch information
emilia-paz authored and Chromium LUCI CQ committed Mar 25, 2023
1 parent 14db69d commit 973395f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 60 deletions.
Expand Up @@ -22,22 +22,6 @@ namespace {

using PermissionsManager = extensions::PermissionsManager;

// Returns whether the extension injected a script by checking the document
// title.
bool DidInjectScript(content::WebContents* web_contents) {
const std::u16string& title = web_contents->GetTitle();
if (title == u"success") {
return true;
}
// The original page title is "OK"; this indicates the script didn't
// inject.
if (title == u"OK") {
return false;
}
ADD_FAILURE() << "Unexpected page title found: " << title;
return false;
}

} // namespace

class ExtensionsMenuMainPageViewInteractiveUITest
Expand All @@ -55,8 +39,6 @@ class ExtensionsMenuMainPageViewInteractiveUITest

void ClickSiteSettingToggle();

ExtensionsToolbarButton* extensions_button();
ExtensionsMenuCoordinator* menu_coordinator();
ExtensionsMenuMainPageView* main_page();

// ExtensionsToolbarUITest:
Expand Down Expand Up @@ -89,17 +71,6 @@ void ExtensionsMenuMainPageViewInteractiveUITest::ClickSiteSettingToggle() {
WaitForAnimation();
}

ExtensionsToolbarButton*
ExtensionsMenuMainPageViewInteractiveUITest::extensions_button() {
return GetExtensionsToolbarContainer()->GetExtensionsButton();
}

ExtensionsMenuCoordinator*
ExtensionsMenuMainPageViewInteractiveUITest::menu_coordinator() {
return GetExtensionsToolbarContainer()
->GetExtensionsMenuCoordinatorForTesting();
}

ExtensionsMenuMainPageView*
ExtensionsMenuMainPageViewInteractiveUITest::main_page() {
ExtensionsMenuViewController* menu_controller =
Expand Down
Expand Up @@ -22,24 +22,6 @@ namespace {

using PermissionsManager = extensions::PermissionsManager;

// Returns whether the extension injected a script by checking the document
// title.
// TODO(crbug.com/1390952): Move repeated code from main page and site
// permissions page interactive ui tests to ExtensionsToolbarUITest.
bool DidInjectScript(content::WebContents* web_contents) {
const std::u16string& title = web_contents->GetTitle();
if (title == u"success") {
return true;
}
// The original page title is "OK"; this indicates the script didn't
// inject.
if (title == u"OK") {
return false;
}
ADD_FAILURE() << "Unexpected page title found: " << title;
return false;
}

} // namespace

class ExtensionsMenuSitePermissionsPageViewInteractiveUITest
Expand All @@ -62,8 +44,6 @@ class ExtensionsMenuSitePermissionsPageViewInteractiveUITest
// opened.
bool IsSitePermissionsPageOpened(extensions::ExtensionId extension_id);

ExtensionsToolbarButton* extensions_button();
ExtensionsMenuCoordinator* menu_coordinator();
ExtensionsMenuMainPageView* main_page();
ExtensionsMenuSitePermissionsPageView* site_permissions_page();

Expand Down Expand Up @@ -100,17 +80,6 @@ bool ExtensionsMenuSitePermissionsPageViewInteractiveUITest::
return page && page->extension_id() == extension_id;
}

ExtensionsToolbarButton*
ExtensionsMenuSitePermissionsPageViewInteractiveUITest::extensions_button() {
return GetExtensionsToolbarContainer()->GetExtensionsButton();
}

ExtensionsMenuCoordinator*
ExtensionsMenuSitePermissionsPageViewInteractiveUITest::menu_coordinator() {
return GetExtensionsToolbarContainer()
->GetExtensionsMenuCoordinatorForTesting();
}

ExtensionsMenuMainPageView*
ExtensionsMenuSitePermissionsPageViewInteractiveUITest::main_page() {
ExtensionsMenuViewController* menu_controller =
Expand Down
Expand Up @@ -173,6 +173,30 @@ ExtensionsToolbarUITest::GetVisibleToolbarActionViews() const {
return views;
}

ExtensionsToolbarButton* ExtensionsToolbarUITest::extensions_button() {
return GetExtensionsToolbarContainer()->GetExtensionsButton();
}

ExtensionsMenuCoordinator* ExtensionsToolbarUITest::menu_coordinator() {
return GetExtensionsToolbarContainer()
->GetExtensionsMenuCoordinatorForTesting();
}

bool ExtensionsToolbarUITest::DidInjectScript(
content::WebContents* web_contents) {
const std::u16string& title = web_contents->GetTitle();
if (title == u"success") {
return true;
}
// The original page title is "OK"; this indicates the script didn't
// inject.
if (title == u"OK") {
return false;
}
ADD_FAILURE() << "Unexpected page title found: " << title;
return false;
}

void ExtensionsToolbarUITest::ClickButton(views::Button* button) const {
ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, 0);
Expand Down
Expand Up @@ -15,6 +15,8 @@

class ExtensionsToolbarContainer;
class ToolbarActionView;
class ExtensionsToolbarButton;
class ExtensionsMenuCoordinator;

namespace extensions {
class Extension;
Expand Down Expand Up @@ -97,9 +99,19 @@ class ExtensionsToolbarUITest : public DialogBrowserTest {
// GetToolbarActionViews().
std::vector<ToolbarActionView*> GetVisibleToolbarActionViews() const;

// Returns the extensions button in the toolbar.
ExtensionsToolbarButton* extensions_button();

// Returns the extensions menu coordinator.
ExtensionsMenuCoordinator* menu_coordinator();

// Triggers the press and release event of the given `button`.
void ClickButton(views::Button* button) const;

// Returns whether the extension injected a script by checking the document
// title. Extension must use 'extensions/blocked_actions/content_scripts'.
bool DidInjectScript(content::WebContents* web_contents);

// Waits for the extensions container to animate (on pin, unpin, pop-out,
// etc.)
void WaitForAnimation();
Expand Down

0 comments on commit 973395f

Please sign in to comment.