Commit f99bc5f7 authored by nancylingwang's avatar nancylingwang Committed by Commit Bot

Fix the flaky browser test LauncherPlatformAppBrowserTest.SetIcon

AppService is used to load icons for windows. AppService uses async
mojom. So it might be not very appropriate to test with update number
when we have the custom icon, because if the icon is updated fast from
AppService, then it might be updated 4 times, however if slow, then
there are 3 updates only, becuase it has got the customer icon, and the
icon update from AppService could be skipped.

Modify the test case LauncherPlatformAppBrowserTest.SetIcon to check
the final image. If the custom icon is set, check the window's icon is
set as the custom icon.

BUG=1115533

Change-Id: Ief034842fef9360a49a504effb54cf51c8d4c51a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2364156Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#800144}
parent c7b40cce
...@@ -887,6 +887,9 @@ IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, SetIcon) { ...@@ -887,6 +887,9 @@ IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, SetIcon) {
gfx::ImageSkia image_skia; gfx::ImageSkia image_skia;
if (base::FeatureList::IsEnabled(features::kAppServiceAdaptiveIcon)) { if (base::FeatureList::IsEnabled(features::kAppServiceAdaptiveIcon)) {
// Only when the kAppServiceAdaptiveIcon feature is enabled, AppService is
// called to load icons for windows. So the image checking is available when
// the kAppServiceAdaptiveIcon feature is enabled.
int32_t size_hint_in_dip = 48; int32_t size_hint_in_dip = 48;
image_skia = app_service_test().LoadAppIconBlocking( image_skia = app_service_test().LoadAppIconBlocking(
apps::mojom::AppType::kExtension, extension->id(), size_hint_in_dip); apps::mojom::AppType::kExtension, extension->id(), size_hint_in_dip);
...@@ -928,18 +931,28 @@ IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, SetIcon) { ...@@ -928,18 +931,28 @@ IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, SetIcon) {
ready_listener.Reset(); ready_listener.Reset();
// Custom icon update. // Custom icon update.
test_observer.WaitForIconUpdate(); test_observer.WaitForIconUpdate();
if (base::FeatureList::IsEnabled(features::kAppServiceAdaptiveIcon)) {
EXPECT_FALSE(app_service_test().AreIconImageEqual(
image_skia, test_observer.last_app_icon()));
}
gfx::ImageSkia custome_icon = test_observer.last_app_icon();
// Create shelf window with custom icon on init. // Create shelf window with custom icon on init.
EXPECT_TRUE(ready_listener.WaitUntilSatisfied()); EXPECT_TRUE(ready_listener.WaitUntilSatisfied());
ready_listener.Reply("createShelfWindowWithCustomIcon"); ready_listener.Reply("createShelfWindowWithCustomIcon");
ready_listener.Reset(); ready_listener.Reset();
int update_number;
if (base::FeatureList::IsEnabled(features::kAppServiceAdaptiveIcon)) { if (base::FeatureList::IsEnabled(features::kAppServiceAdaptiveIcon)) {
// Default app icon + extension icon + AppServiceProxy load icon + custom // Default app icon + extension icon + AppServiceProxy load icon + custom
// icon updates. // icon updates. Ensure the custom icon is set as the window's icon.
test_observer.WaitForIconUpdates(4); test_observer.WaitForIconUpdates(custome_icon);
EXPECT_TRUE(app_service_test().AreIconImageEqual(
custome_icon, test_observer.last_app_icon()));
update_number = test_observer.icon_updates();
} else { } else {
// Default app icon + extension icon + custom icon updates. // Default app icon + extension icon + custom icon updates.
test_observer.WaitForIconUpdates(3); test_observer.WaitForIconUpdates(3);
update_number = test_observer.icon_updates();
} }
const gfx::ImageSkia app_item_custom_image = test_observer.last_app_icon(); const gfx::ImageSkia app_item_custom_image = test_observer.last_app_icon();
...@@ -972,13 +985,9 @@ IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, SetIcon) { ...@@ -972,13 +985,9 @@ IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, SetIcon) {
// No more icon updates. // No more icon updates.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
if (base::FeatureList::IsEnabled(features::kAppServiceAdaptiveIcon)) { EXPECT_TRUE(app_service_test().AreIconImageEqual(
// 3 + 3 + 1 + 4 custome_icon, test_observer.last_app_icon()));
EXPECT_EQ(11, test_observer.icon_updates()); EXPECT_EQ(update_number, test_observer.icon_updates());
} else {
// 2 + 2 + 1 + 3
EXPECT_EQ(8, test_observer.icon_updates());
}
// Exit. // Exit.
EXPECT_TRUE(ready_listener.WaitUntilSatisfied()); EXPECT_TRUE(ready_listener.WaitUntilSatisfied());
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "extensions/browser/app_window/app_window.h" #include "extensions/browser/app_window/app_window.h"
#include "ui/aura/client/aura_constants.h" #include "ui/aura/client/aura_constants.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/gfx/image/image_unittest_util.h"
TestAppWindowIconObserver::TestAppWindowIconObserver( TestAppWindowIconObserver::TestAppWindowIconObserver(
content::BrowserContext* context) content::BrowserContext* context)
...@@ -33,10 +34,17 @@ void TestAppWindowIconObserver::WaitForIconUpdates(int updates) { ...@@ -33,10 +34,17 @@ void TestAppWindowIconObserver::WaitForIconUpdates(int updates) {
expected_icon_updates_ = updates + icon_updates_; expected_icon_updates_ = updates + icon_updates_;
icon_updated_callback_ = run_loop.QuitClosure(); icon_updated_callback_ = run_loop.QuitClosure();
run_loop.Run(); run_loop.Run();
base::RunLoop().RunUntilIdle();
DCHECK_EQ(expected_icon_updates_, icon_updates_); DCHECK_EQ(expected_icon_updates_, icon_updates_);
} }
void TestAppWindowIconObserver::WaitForIconUpdates(
const gfx::ImageSkia& image_skia) {
base::RunLoop run_loop;
expected_image_skia_ = image_skia;
icon_image_updated_callback_ = run_loop.QuitClosure();
run_loop.Run();
}
void TestAppWindowIconObserver::OnAppWindowAdded( void TestAppWindowIconObserver::OnAppWindowAdded(
extensions::AppWindow* app_window) { extensions::AppWindow* app_window) {
aura::Window* window = app_window->GetNativeWindow(); aura::Window* window = app_window->GetNativeWindow();
...@@ -95,4 +103,11 @@ void TestAppWindowIconObserver::OnWindowPropertyChanged(aura::Window* window, ...@@ -95,4 +103,11 @@ void TestAppWindowIconObserver::OnWindowPropertyChanged(aura::Window* window,
!icon_updated_callback_.is_null()) { !icon_updated_callback_.is_null()) {
std::move(icon_updated_callback_).Run(); std::move(icon_updated_callback_).Run();
} }
if (!icon_image_updated_callback_.is_null() &&
gfx::test::AreBitmapsEqual(
expected_image_skia_.GetRepresentation(1.0f).GetBitmap(),
image->GetRepresentation(1.0f).GetBitmap())) {
std::move(icon_image_updated_callback_).Run();
}
} }
...@@ -31,6 +31,8 @@ class TestAppWindowIconObserver ...@@ -31,6 +31,8 @@ class TestAppWindowIconObserver
void WaitForIconUpdate(); void WaitForIconUpdate();
// Waits for |updates| number of icon updates. // Waits for |updates| number of icon updates.
void WaitForIconUpdates(int updates); void WaitForIconUpdates(int updates);
// Waits for icon updates to get |image_skia|.
void WaitForIconUpdates(const gfx::ImageSkia& image_skia);
int icon_updates() const { return icon_updates_; } int icon_updates() const { return icon_updates_; }
...@@ -53,6 +55,8 @@ class TestAppWindowIconObserver ...@@ -53,6 +55,8 @@ class TestAppWindowIconObserver
std::map<aura::Window*, std::string> last_app_icon_hash_map_; std::map<aura::Window*, std::string> last_app_icon_hash_map_;
base::OnceClosure icon_updated_callback_; base::OnceClosure icon_updated_callback_;
gfx::ImageSkia last_app_icon_; gfx::ImageSkia last_app_icon_;
gfx::ImageSkia expected_image_skia_;
base::OnceClosure icon_image_updated_callback_;
DISALLOW_COPY_AND_ASSIGN(TestAppWindowIconObserver); DISALLOW_COPY_AND_ASSIGN(TestAppWindowIconObserver);
}; };
......
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