Commit 221a0ca2 authored by Devlin Cronin's avatar Devlin Cronin Committed by Commit Bot

[Extensions] Add a simple end-to-end MV3 test for the "action" API

Bug: 993912
Change-Id: I76590932b60aeda6faef7e0b16ae35b0f38c3a27
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1761520
Commit-Queue: Devlin <rdevlin.cronin@chromium.org>
Reviewed-by: default avatarIstiaque Ahmed <lazyboy@chromium.org>
Reviewed-by: default avatarKelvin Jiang <kelvinjiang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#690042}
parent b1d5c8d4
......@@ -6,6 +6,7 @@
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/extensions/browser_action_test_util.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/version_info/channel.h"
......@@ -31,6 +32,15 @@ class ManifestV3BrowserTest : public ExtensionBrowserTest {
ASSERT_TRUE(embedded_test_server()->Start());
}
// Loads and returns an extension while ignoring warnings.
const Extension* LoadMv3Extension(const base::FilePath& path) {
// We ignore the manifest warnings on the extension because it includes the
// "manifest v3 ain't quite ready yet" warning.
// TODO(devlin): We should probably introduce a flag to specifically ignore
// *that* warning, but no others.
return LoadExtensionWithFlags(path, kFlagIgnoreManifestWarnings);
}
private:
ScopedCurrentChannel channel_override_{version_info::Channel::UNKNOWN};
......@@ -76,12 +86,7 @@ IN_PROC_BROWSER_TEST_F(ManifestV3BrowserTest, ProgrammaticScriptInjection) {
test_dir.WriteFile(FILE_PATH_LITERAL("worker.js"), kWorker);
ExtensionTestMessageListener listener("ready", /*will_reply=*/false);
// We ignore the manifest warnings on the extension because it includes the
// "manifest v3 ain't quite ready yet" warning.
// TODO(devlin): We should probably introduce a flag to specifically ignore
// *that* warning, but no others.
const Extension* extension = LoadExtensionWithFlags(
test_dir.UnpackedPath(), kFlagIgnoreManifestWarnings);
const Extension* extension = LoadMv3Extension(test_dir.UnpackedPath());
ASSERT_TRUE(extension);
ASSERT_TRUE(listener.WaitUntilSatisfied());
......@@ -94,4 +99,41 @@ IN_PROC_BROWSER_TEST_F(ManifestV3BrowserTest, ProgrammaticScriptInjection) {
browser()->tab_strip_model()->GetActiveWebContents()->GetTitle());
}
// A simple end-to-end test exercising the new action API in Manifest V3.
// More robust tests for the action API are in extension_action_apitest.cc.
IN_PROC_BROWSER_TEST_F(ManifestV3BrowserTest, ActionAPI) {
constexpr char kManifest[] =
R"({
"name": "Action API",
"manifest_version": 3,
"version": "0.1",
"background": { "service_worker": "worker.js" },
"action": {}
})";
constexpr char kWorker[] =
R"(chrome.action.onClicked.addListener((tab) => {
chrome.test.assertTrue(!!tab);
chrome.test.notifyPass();
});
chrome.test.sendMessage('ready');)";
TestExtensionDir test_dir;
test_dir.WriteManifest(kManifest);
test_dir.WriteFile(FILE_PATH_LITERAL("worker.js"), kWorker);
ExtensionTestMessageListener listener("ready", /*will_reply=*/false);
const Extension* extension = LoadMv3Extension(test_dir.UnpackedPath());
ASSERT_TRUE(extension);
ASSERT_TRUE(listener.WaitUntilSatisfied());
std::unique_ptr<BrowserActionTestUtil> action_test_util =
BrowserActionTestUtil::Create(browser());
ASSERT_EQ(1, action_test_util->NumberOfBrowserActions());
EXPECT_EQ(extension->id(), action_test_util->GetExtensionId(0));
ResultCatcher catcher;
action_test_util->Press(0);
ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
}
} // namespace extensions
......@@ -59,7 +59,8 @@
},
"action": {
"dependencies": ["manifest:action"],
"contexts": ["blessed_extension"]
"contexts": ["blessed_extension"],
"disallow_for_service_workers": false
},
"activityLogPrivate": [{
"dependencies": ["permission:activityLogPrivate"],
......
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