Commit 8d170b87 authored by dpapad's avatar dpapad Committed by Commit Bot

MD Extensions: Port LazyBackgroundPageApiTest.UpdateExtensionsPage to new UI.

Bug: 800502
Change-Id: I059c10360312df02b040e3e87667b8a39abce09c
Reviewed-on: https://chromium-review.googlesource.com/891627Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Commit-Queue: Demetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#532714}
parent 2b7debd2
...@@ -22,9 +22,11 @@ ...@@ -22,9 +22,11 @@
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/location_bar/location_bar.h" #include "chrome/browser/ui/location_bar/location_bar.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/api/tabs.h" #include "chrome/common/extensions/api/tabs.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "components/app_modal/javascript_app_modal_dialog.h" #include "components/app_modal/javascript_app_modal_dialog.h"
...@@ -619,6 +621,82 @@ IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, UpdateExtensionsPage) { ...@@ -619,6 +621,82 @@ IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, UpdateExtensionsPage) {
" ele[0].innerHTML.search('(Inactive)') > 0);", " ele[0].innerHTML.search('(Inactive)') > 0);",
&is_inactive)); &is_inactive));
} }
EXPECT_TRUE(is_inactive);
}
// TODO(dpapad): Remove the _MD suffix once the non-MD test is deleted.
IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, UpdateExtensionsPage_MD) {
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitWithFeatures(
{features::kMaterialDesignExtensions} /* enabled */, {} /* disabled */);
// Need to turn on developer mode, otherwise the info to be tested is not
// displayed in chrome://extensions.
browser()->profile()->GetPrefs()->SetBoolean(
prefs::kExtensionsUIDeveloperMode, true);
// Need to get the extension ID first, before opening the corresponding
// details page on chrome://extensions.
ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL));
ResultCatcher catcher;
base::FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page")
.AppendASCII("wait_for_view");
const Extension* extension = LoadExtension(extdir);
ASSERT_TRUE(extension);
EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
// The extension should've opened a new tab to an extension page.
EXPECT_EQ(
extension->GetResourceURL("extension_page.html").spec(),
browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec());
browser()->tab_strip_model()->ActivateTabAt(0, false);
std::string details_page_url = chrome::kChromeUIExtensionsURL;
details_page_url += "?id=" + extension->id();
ui_test_utils::NavigateToURL(browser(), GURL(details_page_url));
auto* extensions_page = browser()->tab_strip_model()->GetActiveWebContents();
// Lazy Background Page still exists, because the extension created a new tab
// to an extension page.
EXPECT_TRUE(IsBackgroundPageAlive(last_loaded_extension_id()));
// Close the new tab.
LazyBackgroundObserver page_complete;
browser()->tab_strip_model()->CloseWebContentsAt(1,
TabStripModel::CLOSE_NONE);
page_complete.WaitUntilClosed();
// Lazy Background Page has been shut down.
EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
// Updating the extensions page is a process that has back-and-forth
// communication (i.e., backend tells extensions page something changed,
// extensions page requests updated data, backend responds with updated data,
// and so forth). This makes it difficult to know for sure when the page is
// done updating, so just try a few times. We limit the total number of
// attempts so that a) the test *fails* (instead of times out), and b) we
// know we're not making a ridiculous amount of trips to update the page.
const char setup_js[] =
R"(const detailView = document.querySelector('extensions-manager').
shadowRoot.querySelector('extensions-detail-view');
const inspectableViews = detailView.shadowRoot.querySelector(
'#inspectable-views');
)";
EXPECT_TRUE(
content::ExecuteScript(extensions_page, base::StringPrintf(setup_js)));
bool is_inactive = false;
int kMaxTries = 10;
int num_tries = 0;
while (!is_inactive && num_tries++ < kMaxTries) {
EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
extensions_page,
"window.domAutomationController.send("
" inspectableViews.innerHTML.includes('(Inactive)'));",
&is_inactive));
}
EXPECT_TRUE(is_inactive);
} }
// Tests that the lazy background page will be unloaded if the onSuspend event // Tests that the lazy background page will be unloaded if the onSuspend event
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment