summaryrefslogtreecommitdiffstats
path: root/chromium/chrome/browser/extensions/api/extension_action
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2021-10-26 13:57:00 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2021-11-02 11:31:01 +0000
commit1943b3c2a1dcee36c233724fc4ee7613d71b9cf6 (patch)
tree8c1b5f12357025c197da5427ae02cfdc2f3570d6 /chromium/chrome/browser/extensions/api/extension_action
parent21ba0c5d4bf8fba15dddd97cd693bad2358b77fd (diff)
BASELINE: Update Chromium to 94.0.4606.111
Change-Id: I924781584def20fc800bedf6ff41fdb96c438193 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/chrome/browser/extensions/api/extension_action')
-rw-r--r--chromium/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc94
-rw-r--r--chromium/chrome/browser/extensions/api/extension_action/browser_action_interactive_test.cc19
-rw-r--r--chromium/chrome/browser/extensions/api/extension_action/extension_action_api.cc22
-rw-r--r--chromium/chrome/browser/extensions/api/extension_action/page_action_apitest.cc8
4 files changed, 85 insertions, 58 deletions
diff --git a/chromium/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc b/chromium/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc
index f2719e661a7..93cd9dfd4b4 100644
--- a/chromium/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc
+++ b/chromium/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc
@@ -104,8 +104,10 @@ void VerifyIconsMatch(const gfx::Image& bar_rendering,
class BrowserActionApiTest : public ExtensionApiTest {
public:
- BrowserActionApiTest() {}
- ~BrowserActionApiTest() override {}
+ BrowserActionApiTest() = default;
+ ~BrowserActionApiTest() override = default;
+ BrowserActionApiTest(const BrowserActionApiTest&) = delete;
+ BrowserActionApiTest& operator=(const BrowserActionApiTest&) = delete;
void TearDownOnMainThread() override {
// Clean up the test util first, so that any created UI properly removes
@@ -133,12 +135,12 @@ class BrowserActionApiTest : public ExtensionApiTest {
private:
std::unique_ptr<ExtensionActionTestHelper> browser_action_test_util_;
-
- DISALLOW_COPY_AND_ASSIGN(BrowserActionApiTest);
};
// Canvas tests rely on the harness producing pixel output in order to read back
// pixels from a canvas element. So we have to override the setup function.
+// TODO(https://crbug.com/1093066): Investigate to see if these tests can be
+// enabled for Service Worker-based extensions.
class BrowserActionApiCanvasTest : public BrowserActionApiTest {
public:
void SetUp() override {
@@ -149,9 +151,17 @@ class BrowserActionApiCanvasTest : public BrowserActionApiTest {
using ContextType = ExtensionBrowserTest::ContextType;
-class BrowserActionApiLazyTest
+class BrowserActionApiTestWithContextType
: public BrowserActionApiTest,
public testing::WithParamInterface<ContextType> {
+ public:
+ BrowserActionApiTestWithContextType() = default;
+ ~BrowserActionApiTestWithContextType() override = default;
+ BrowserActionApiTestWithContextType(
+ const BrowserActionApiTestWithContextType&) = delete;
+ BrowserActionApiTestWithContextType& operator=(
+ const BrowserActionApiTestWithContextType&) = delete;
+
protected:
const extensions::Extension* LoadExtensionWithParamOptions(
const base::FilePath& path) {
@@ -225,11 +235,17 @@ class BrowserActionApiLazyTest
action->GetIsVisible(ExtensionAction::kDefaultTabId));
}
+ bool RunTest(const char* name) WARN_UNUSED_RESULT {
+ return RunExtensionTest(
+ name, {},
+ {.load_as_service_worker = GetParam() == ContextType::kServiceWorker});
+ }
+
private:
base::test::ScopedFeatureList feature_list_;
};
-IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, Basic) {
+IN_PROC_BROWSER_TEST_P(BrowserActionApiTestWithContextType, Basic) {
ExtensionTestMessageListener ready_listener("ready", false);
ASSERT_TRUE(embedded_test_server()->Start());
const Extension* extension = LoadExtensionWithParamOptions(
@@ -253,19 +269,19 @@ IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, Basic) {
EXPECT_TRUE(catcher.GetNextResult());
}
-IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, Disable) {
+IN_PROC_BROWSER_TEST_P(BrowserActionApiTestWithContextType, Disable) {
ASSERT_NO_FATAL_FAILURE(RunEnableTest("browser_action/enable", true));
}
-IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, Enable) {
+IN_PROC_BROWSER_TEST_P(BrowserActionApiTestWithContextType, Enable) {
ASSERT_NO_FATAL_FAILURE(RunEnableTest("browser_action/enable", false));
}
-IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, Update) {
+IN_PROC_BROWSER_TEST_P(BrowserActionApiTestWithContextType, Update) {
ASSERT_NO_FATAL_FAILURE(RunUpdateTest("browser_action/update", false));
}
-IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, UpdateSvg) {
+IN_PROC_BROWSER_TEST_P(BrowserActionApiTestWithContextType, UpdateSvg) {
// TODO(crbug.com/1064671): Service Workers currently don't support loading
// SVG images.
const bool expect_failure = GetParam() == ContextType::kServiceWorker;
@@ -273,11 +289,11 @@ IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, UpdateSvg) {
RunUpdateTest("browser_action/update_svg", expect_failure));
}
-INSTANTIATE_TEST_SUITE_P(EventPage,
- BrowserActionApiLazyTest,
- ::testing::Values(ContextType::kEventPage));
+INSTANTIATE_TEST_SUITE_P(PersistentBackground,
+ BrowserActionApiTestWithContextType,
+ ::testing::Values(ContextType::kPersistentBackground));
INSTANTIATE_TEST_SUITE_P(ServiceWorker,
- BrowserActionApiLazyTest,
+ BrowserActionApiTestWithContextType,
::testing::Values(ContextType::kServiceWorker));
IN_PROC_BROWSER_TEST_F(BrowserActionApiCanvasTest, DynamicBrowserAction) {
@@ -288,10 +304,10 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiCanvasTest, DynamicBrowserAction) {
#if defined(OS_MAC)
// We need this on mac so we don't loose 2x representations from browser icon
// in transformations gfx::ImageSkia -> NSImage -> gfx::ImageSkia.
- std::vector<ui::ScaleFactor> supported_scale_factors;
+ std::vector<ui::ResourceScaleFactor> supported_scale_factors;
supported_scale_factors.push_back(ui::SCALE_FACTOR_100P);
supported_scale_factors.push_back(ui::SCALE_FACTOR_200P);
- ui::SetSupportedScaleFactors(supported_scale_factors);
+ ui::SetSupportedResourceScaleFactors(supported_scale_factors);
#endif
// We should not be creating icons asynchronously, so we don't need an
@@ -523,10 +539,9 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiCanvasTest, InvisibleIconBrowserAction) {
}
}
-IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest,
+IN_PROC_BROWSER_TEST_P(BrowserActionApiTestWithContextType,
TabSpecificBrowserActionState) {
- ASSERT_TRUE(RunExtensionTest("browser_action/tab_specific_state")) <<
- message_;
+ ASSERT_TRUE(RunTest("browser_action/tab_specific_state")) << message_;
const Extension* extension = GetSingleLoadedExtension();
ASSERT_TRUE(extension) << message_;
@@ -558,8 +573,8 @@ IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest,
// Test that calling chrome.browserAction.setIcon() can set the icon for
// extension.
-IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, BrowserActionSetIcon) {
- ASSERT_TRUE(RunExtensionTest("browser_action/set_icon")) << message_;
+IN_PROC_BROWSER_TEST_P(BrowserActionApiTestWithContextType, SetIcon) {
+ ASSERT_TRUE(RunTest("browser_action/set_icon")) << message_;
const Extension* extension = GetSingleLoadedExtension();
ASSERT_TRUE(extension) << message_;
@@ -592,8 +607,8 @@ IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, BrowserActionSetIcon) {
// Test that calling chrome.browserAction.setPopup() can enable and change
// a popup.
-IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, BrowserActionAddPopup) {
- ASSERT_TRUE(RunExtensionTest("browser_action/add_popup")) << message_;
+IN_PROC_BROWSER_TEST_P(BrowserActionApiTestWithContextType, AddPopup) {
+ ASSERT_TRUE(RunTest("browser_action/add_popup")) << message_;
const Extension* extension = GetSingleLoadedExtension();
ASSERT_TRUE(extension) << message_;
@@ -647,9 +662,9 @@ IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, BrowserActionAddPopup) {
}
// Test that calling chrome.browserAction.setPopup() can remove a popup.
-IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, BrowserActionRemovePopup) {
+IN_PROC_BROWSER_TEST_P(BrowserActionApiTestWithContextType, RemovePopup) {
// Load the extension, which has a browser action with a default popup.
- ASSERT_TRUE(RunExtensionTest("browser_action/remove_popup")) << message_;
+ ASSERT_TRUE(RunTest("browser_action/remove_popup")) << message_;
const Extension* extension = GetSingleLoadedExtension();
ASSERT_TRUE(extension) << message_;
@@ -681,7 +696,7 @@ IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, BrowserActionRemovePopup) {
<< "a specific tab id.";
}
-IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, IncognitoBasic) {
+IN_PROC_BROWSER_TEST_P(BrowserActionApiTestWithContextType, IncognitoBasic) {
ExtensionTestMessageListener ready_listener("ready", false);
ASSERT_TRUE(embedded_test_server()->Start());
scoped_refptr<const Extension> extension = LoadExtensionWithParamOptions(
@@ -729,7 +744,7 @@ IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, IncognitoBasic) {
EXPECT_TRUE(catcher.GetNextResult());
}
-IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, IncognitoUpdate) {
+IN_PROC_BROWSER_TEST_P(BrowserActionApiTestWithContextType, IncognitoUpdate) {
ASSERT_TRUE(embedded_test_server()->Start());
ExtensionTestMessageListener incognito_not_allowed_listener(
"incognito not allowed", false);
@@ -792,7 +807,10 @@ IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, IncognitoUpdate) {
// Tests that events are dispatched to the correct profile for split mode
// extensions.
-IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, IncognitoSplit) {
+// TODO(https://crbug.com/1212866): Crashes or times out when running as a
+// Service Worker-based extension. When fixed, make this a
+// BrowserActionApiTestWithContextType test.
+IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, IncognitoSplit) {
ResultCatcher catcher;
const Extension* extension =
LoadExtension(test_data_dir_.AppendASCII("browser_action/split_mode"),
@@ -873,9 +891,10 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, CloseBackgroundPage) {
action->GetExplicitlySetBadgeText(ExtensionAction::kDefaultTabId));
}
-IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, BadgeBackgroundColor) {
+IN_PROC_BROWSER_TEST_P(BrowserActionApiTestWithContextType,
+ BadgeBackgroundColor) {
ASSERT_TRUE(embedded_test_server()->Start());
- ASSERT_TRUE(RunExtensionTest("browser_action/color")) << message_;
+ ASSERT_TRUE(RunTest("browser_action/color")) << message_;
const Extension* extension = GetSingleLoadedExtension();
ASSERT_TRUE(extension) << message_;
@@ -922,8 +941,8 @@ IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, BadgeBackgroundColor) {
action->GetBadgeBackgroundColor(ExtensionAction::kDefaultTabId));
}
-IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, Getters) {
- ASSERT_TRUE(RunExtensionTest("browser_action/getters")) << message_;
+IN_PROC_BROWSER_TEST_P(BrowserActionApiTestWithContextType, Getters) {
+ ASSERT_TRUE(RunTest("browser_action/getters")) << message_;
const Extension* extension = GetSingleLoadedExtension();
ASSERT_TRUE(extension) << message_;
@@ -943,10 +962,11 @@ IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, Getters) {
}
// Verify triggering browser action.
-IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, TestTriggerBrowserAction) {
+IN_PROC_BROWSER_TEST_P(BrowserActionApiTestWithContextType,
+ TestTriggerBrowserAction) {
ASSERT_TRUE(embedded_test_server()->Start());
- ASSERT_TRUE(RunExtensionTest("trigger_actions/browser_action")) << message_;
+ ASSERT_TRUE(RunTest("trigger_actions/browser_action")) << message_;
const Extension* extension = GetSingleLoadedExtension();
ASSERT_TRUE(extension) << message_;
@@ -979,11 +999,11 @@ IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, TestTriggerBrowserAction) {
EXPECT_EQ(result, "red");
}
-IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest,
- BrowserActionWithRectangularIcon) {
+IN_PROC_BROWSER_TEST_P(BrowserActionApiTestWithContextType,
+ WithRectangularIcon) {
ExtensionTestMessageListener ready_listener("ready", true);
- const Extension* extension = LoadExtension(
+ const Extension* extension = LoadExtensionWithParamOptions(
test_data_dir_.AppendASCII("browser_action").AppendASCII("rect_icon"));
ASSERT_TRUE(extension);
EXPECT_TRUE(ready_listener.WaitUntilSatisfied());
diff --git a/chromium/chrome/browser/extensions/api/extension_action/browser_action_interactive_test.cc b/chromium/chrome/browser/extensions/api/extension_action/browser_action_interactive_test.cc
index d66951a5d4b..2d7dc883530 100644
--- a/chromium/chrome/browser/extensions/api/extension_action/browser_action_interactive_test.cc
+++ b/chromium/chrome/browser/extensions/api/extension_action/browser_action_interactive_test.cc
@@ -158,8 +158,8 @@ class BrowserActionInteractiveTest : public ExtensionApiTest {
if (!will_reply)
listener = std::make_unique<ExtensionTestMessageListener>("ready", false);
// Show first popup in first window and expect it to have loaded.
- ASSERT_TRUE(RunExtensionTest({.name = "browser_action/open_popup",
- .page_url = "open_popup_succeeds.html"}))
+ ASSERT_TRUE(RunExtensionTest("browser_action/open_popup",
+ {.page_url = "open_popup_succeeds.html"}))
<< message_;
if (listener)
EXPECT_TRUE(listener->WaitUntilSatisfied());
@@ -228,7 +228,8 @@ class BrowserActionInteractiveTest : public ExtensionApiTest {
// Tests opening a popup using the chrome.browserAction.openPopup API. This test
// opens a popup in the starting window, closes the popup, creates a new window
// and opens a popup in the new window. Both popups should succeed in opening.
-IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, TestOpenPopup) {
+// TODO(crbug.com/1233996): Test flaking frequently.
+IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, DISABLED_TestOpenPopup) {
auto browserActionBar = ExtensionActionTestHelper::Create(browser());
// Setup extension message listener to wait for javascript to finish running.
ExtensionTestMessageListener listener("ready", true);
@@ -277,10 +278,10 @@ IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, TestOpenPopupIncognito) {
content::WindowedNotificationObserver frame_observer(
content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
content::NotificationService::AllSources());
- ASSERT_TRUE(RunExtensionTest({.name = "browser_action/open_popup",
- .page_url = "open_popup_succeeds.html",
- .open_in_incognito = true},
- {.allow_in_incognito = true}))
+ ASSERT_TRUE(RunExtensionTest(
+ "browser_action/open_popup",
+ {.page_url = "open_popup_succeeds.html", .open_in_incognito = true},
+ {.allow_in_incognito = true}))
<< message_;
frame_observer.Wait();
// Non-Aura Linux uses a singleton for the popup, so it looks like all windows
@@ -330,8 +331,8 @@ IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest,
ExtensionTestMessageListener listener("ready", true);
// Load the test extension which will do nothing except notifyPass() to
// return control here.
- ASSERT_TRUE(RunExtensionTest({.name = "browser_action/open_popup",
- .page_url = "open_popup_fails.html"}))
+ ASSERT_TRUE(RunExtensionTest("browser_action/open_popup",
+ {.page_url = "open_popup_fails.html"}))
<< message_;
EXPECT_TRUE(listener.WaitUntilSatisfied());
diff --git a/chromium/chrome/browser/extensions/api/extension_action/extension_action_api.cc b/chromium/chrome/browser/extensions/api/extension_action/extension_action_api.cc
index 27606aa96b9..6463c89b6e4 100644
--- a/chromium/chrome/browser/extensions/api/extension_action/extension_action_api.cc
+++ b/chromium/chrome/browser/extensions/api/extension_action/extension_action_api.cc
@@ -9,12 +9,12 @@
#include <utility>
#include "base/bind.h"
+#include "base/cxx17_backports.h"
#include "base/lazy_instance.h"
#include "base/location.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/single_thread_task_runner.h"
-#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/values.h"
@@ -225,8 +225,8 @@ void ExtensionActionAPI::DispatchEventToExtension(
if (!EventRouter::Get(context))
return;
- auto event = std::make_unique<Event>(histogram_value, event_name,
- event_args->TakeList(), context);
+ auto event = std::make_unique<Event>(
+ histogram_value, event_name, std::move(*event_args).TakeList(), context);
event->user_gesture = EventRouter::USER_GESTURE_ENABLED;
EventRouter::Get(context)
->DispatchEventToExtension(extension_id, std::move(event));
@@ -475,24 +475,24 @@ ExtensionActionSetBadgeTextFunction::RunExtensionAction() {
ExtensionFunction::ResponseAction
ExtensionActionSetBadgeBackgroundColorFunction::RunExtensionAction() {
EXTENSION_FUNCTION_VALIDATE(details_);
- base::Value* color_value = NULL;
- EXTENSION_FUNCTION_VALIDATE(details_->Get("color", &color_value));
+ base::Value* color_value = details_->FindKey("color");
+ EXTENSION_FUNCTION_VALIDATE(color_value);
SkColor color = 0;
if (color_value->is_list()) {
- base::ListValue* list = NULL;
- EXTENSION_FUNCTION_VALIDATE(details_->GetList("color", &list));
- EXTENSION_FUNCTION_VALIDATE(list->GetSize() == 4);
+ base::Value::ConstListView list = color_value->GetList();
+
+ EXTENSION_FUNCTION_VALIDATE(list.size() == 4);
int color_array[4] = {0};
for (size_t i = 0; i < base::size(color_array); ++i) {
- EXTENSION_FUNCTION_VALIDATE(list->GetInteger(i, &color_array[i]));
+ EXTENSION_FUNCTION_VALIDATE(list[i].is_int());
+ color_array[i] = list[i].GetInt();
}
color = SkColorSetARGB(color_array[3], color_array[0],
color_array[1], color_array[2]);
} else if (color_value->is_string()) {
- std::string color_string;
- EXTENSION_FUNCTION_VALIDATE(details_->GetString("color", &color_string));
+ std::string color_string = color_value->GetString();
if (!image_util::ParseCssColorString(color_string, &color))
return RespondNow(Error(kInvalidColorError));
}
diff --git a/chromium/chrome/browser/extensions/api/extension_action/page_action_apitest.cc b/chromium/chrome/browser/extensions/api/extension_action/page_action_apitest.cc
index 2c2c2b38b95..002338fa762 100644
--- a/chromium/chrome/browser/extensions/api/extension_action/page_action_apitest.cc
+++ b/chromium/chrome/browser/extensions/api/extension_action/page_action_apitest.cc
@@ -35,6 +35,12 @@ using ContextType = ExtensionBrowserTest::ContextType;
class PageActionApiTest : public ExtensionApiTest,
public testing::WithParamInterface<ContextType> {
+ public:
+ PageActionApiTest() = default;
+ ~PageActionApiTest() override = default;
+ PageActionApiTest(const PageActionApiTest&) = delete;
+ PageActionApiTest& operator=(const PageActionApiTest&) = delete;
+
protected:
ExtensionAction* GetPageAction(const Extension& extension) {
ExtensionAction* extension_action =
@@ -47,7 +53,7 @@ class PageActionApiTest : public ExtensionApiTest,
bool RunTest(const char* name) {
return RunExtensionTest(
- {.name = name},
+ name, {},
{.load_as_service_worker = GetParam() == ContextType::kServiceWorker});
}
};