Chromium Code Reviews| Index: chrome/browser/android/manifest_icon_selector_unittest.cc |
| diff --git a/chrome/browser/android/shortcut_helper_unittest.cc b/chrome/browser/android/manifest_icon_selector_unittest.cc |
| similarity index 87% |
| rename from chrome/browser/android/shortcut_helper_unittest.cc |
| rename to chrome/browser/android/manifest_icon_selector_unittest.cc |
| index 76e1a5e239c2f9eed0cb9f3ca01fa1c19f8a4ab2..1d158072de91b70982ee8688cdee4e831c0badd8 100644 |
| --- a/chrome/browser/android/shortcut_helper_unittest.cc |
| +++ b/chrome/browser/android/manifest_icon_selector_unittest.cc |
| @@ -1,8 +1,8 @@ |
| -// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "chrome/browser/android/shortcut_helper.h" |
| +#include "chrome/browser/android/manifest_icon_selector.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| @@ -10,15 +10,21 @@ |
| #include "ui/gfx/screen.h" |
| #include "ui/gfx/screen_type_delegate.h" |
| -// A dummy implementation of gfx::Screen, since ShortcutHelper needs access to |
| -// a gfx::Display's device scale factor. |
| +namespace { |
| + |
| +const int kPreferredIconSize = 48; |
| + |
| +} |
| + |
| +// A dummy implementation of gfx::Screen, since ManifestIconSelector needs |
| +// access to a gfx::Display's device scale factor. |
| // This is inspired by web_contents_video_capture_device_unittest.cc |
| // A bug has been opened to merge all those mocks: http://crbug.com/417227 |
| class FakeScreen : public gfx::Screen { |
| public: |
| FakeScreen() : display_(0x1337, gfx::Rect(0, 0, 2560, 1440)) { |
| } |
| - virtual ~FakeScreen() {} |
| + ~FakeScreen() override {} |
| void SetDisplayDeviceScaleFactor(float device_scale_factor) { |
| display_.set_device_scale_factor(device_scale_factor); |
| @@ -26,9 +32,9 @@ class FakeScreen : public gfx::Screen { |
| // gfx::Screen implementation (only what's needed for testing). |
| virtual gfx::Point GetCursorScreenPoint() override { return gfx::Point(); } |
| - virtual gfx::NativeWindow GetWindowUnderCursor() override { return NULL; } |
| + virtual gfx::NativeWindow GetWindowUnderCursor() override { return nullptr; } |
| virtual gfx::NativeWindow GetWindowAtScreenPoint( |
| - const gfx::Point& point) override { return NULL; } |
| + const gfx::Point& point) override { return nullptr; } |
| virtual int GetNumDisplays() const override { return 1; } |
| virtual std::vector<gfx::Display> GetAllDisplays() const override { |
| return std::vector<gfx::Display>(1, display_); |
| @@ -57,59 +63,35 @@ class FakeScreen : public gfx::Screen { |
| DISALLOW_COPY_AND_ASSIGN(FakeScreen); |
| }; |
| -class ShortcutHelperTest : public ChromeRenderViewHostTestHarness { |
| +class ManifestIconSelectorTest : public ChromeRenderViewHostTestHarness { |
|
mlamouri (slow - plz ping)
2015/02/03 17:14:14
If you remove the WebContents dependency on the he
gone
2015/02/03 19:25:06
Done.
|
| protected: |
| - ShortcutHelperTest() : shortcut_helper_(NULL) {} |
| - virtual ~ShortcutHelperTest() {} |
| - |
| - static jobject CreateShortcutHelperJava(JNIEnv* env) { |
| - jclass clazz = env->FindClass("org/chromium/chrome/browser/ShortcutHelper"); |
| - jmethodID constructor = |
| - env->GetMethodID(clazz, "<init>", |
| - "(Landroid/content/Context;" |
| - "Lorg/chromium/chrome/browser/Tab;)V"); |
| - return env->NewObject(clazz, constructor, jobject(), jobject()); |
| - } |
| - |
| - void ResetShorcutHelper() { |
| - if (shortcut_helper_) |
| - delete shortcut_helper_; |
| - |
| - JNIEnv* env = base::android::AttachCurrentThread(); |
| - shortcut_helper_ = |
| - new ShortcutHelper(env, CreateShortcutHelperJava(env), web_contents()); |
| - } |
| + ManifestIconSelectorTest() {} |
| + ~ManifestIconSelectorTest() override {} |
| virtual void SetUp() override { |
| gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, &fake_screen_); |
| ASSERT_EQ(&fake_screen_, gfx::Screen::GetNativeScreen()); |
| - |
| ChromeRenderViewHostTestHarness::SetUp(); |
| - |
| - ResetShorcutHelper(); |
| } |
| virtual void TearDown() override { |
| - delete shortcut_helper_; |
| - shortcut_helper_ = NULL; |
| - |
| ChromeRenderViewHostTestHarness::TearDown(); |
| - |
| - gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, NULL); |
| + gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, nullptr); |
| } |
| GURL FindBestMatchingIcon(const std::vector<content::Manifest::Icon>& icons) { |
| - return shortcut_helper_->FindBestMatchingIcon(icons); |
| + return ManifestIconSelector::FindBestMatchingIcon( |
| + icons, |
| + GetPreferredIconSizeInDp(), |
| + web_contents()); |
| } |
| void SetDisplayDeviceScaleFactor(float device_scale_factor) { |
| fake_screen_.SetDisplayDeviceScaleFactor(device_scale_factor); |
| - |
| - ResetShorcutHelper(); |
| } |
| static int GetPreferredIconSizeInDp() { |
| - return ShortcutHelper::kPreferredIconSizeInDp; |
| + return kPreferredIconSize; |
| } |
| static content::Manifest::Icon CreateIcon( |
| @@ -128,20 +110,19 @@ class ShortcutHelperTest : public ChromeRenderViewHostTestHarness { |
| } |
| private: |
| - ShortcutHelper* shortcut_helper_; |
| FakeScreen fake_screen_; |
| - DISALLOW_COPY_AND_ASSIGN(ShortcutHelperTest); |
| + DISALLOW_COPY_AND_ASSIGN(ManifestIconSelectorTest); |
| }; |
| -TEST_F(ShortcutHelperTest, NoIcons) { |
| +TEST_F(ManifestIconSelectorTest, NoIcons) { |
| // No icons should return the empty URL. |
| std::vector<content::Manifest::Icon> icons; |
| GURL url = FindBestMatchingIcon(icons); |
| EXPECT_TRUE(url.is_empty()); |
| } |
| -TEST_F(ShortcutHelperTest, NoSizes) { |
| +TEST_F(ManifestIconSelectorTest, NoSizes) { |
| // Icon with no sizes are ignored. |
| std::vector<content::Manifest::Icon> icons; |
| icons.push_back( |
| @@ -151,7 +132,7 @@ TEST_F(ShortcutHelperTest, NoSizes) { |
| EXPECT_TRUE(url.is_empty()); |
| } |
| -TEST_F(ShortcutHelperTest, MIMETypeFiltering) { |
| +TEST_F(ManifestIconSelectorTest, MIMETypeFiltering) { |
| // Icons with type specified to a MIME type that isn't a valid image MIME type |
| // are ignored. |
| std::vector<gfx::Size> sizes; |
| @@ -187,7 +168,7 @@ TEST_F(ShortcutHelperTest, MIMETypeFiltering) { |
| EXPECT_EQ("http://foo.com/icon.png", url.spec()); |
| } |
| -TEST_F(ShortcutHelperTest, PreferredSizeOfCurrentDensityIsUsedFirst) { |
| +TEST_F(ManifestIconSelectorTest, PreferredSizeOfCurrentDensityIsUsedFirst) { |
| // This test has three icons each are marked with sizes set to the preferred |
| // icon size for the associated density. |
| std::vector<gfx::Size> sizes_1; |
| @@ -220,7 +201,7 @@ TEST_F(ShortcutHelperTest, PreferredSizeOfCurrentDensityIsUsedFirst) { |
| EXPECT_EQ("http://foo.com/icon_x3.png", url.spec()); |
| } |
| -TEST_F(ShortcutHelperTest, PreferredSizeOfDefaultDensityIsUsedSecond) { |
| +TEST_F(ManifestIconSelectorTest, PreferredSizeOfDefaultDensityIsUsedSecond) { |
| // This test has three icons. The first one is of density zero and is marked |
| // with three sizes which are the preferred icon size for density 1, 2 and 3. |
| // The icon for density 2 and 3 have a size set to 2x2 and 3x3. |
| @@ -258,7 +239,7 @@ TEST_F(ShortcutHelperTest, PreferredSizeOfDefaultDensityIsUsedSecond) { |
| EXPECT_EQ("http://foo.com/icon_x1.png", url.spec()); |
| } |
| -TEST_F(ShortcutHelperTest, DeviceDensityFirst) { |
| +TEST_F(ManifestIconSelectorTest, DeviceDensityFirst) { |
| // If there is no perfect icon but an icon of the current device density is |
| // present, it will be picked. |
| // This test has three icons each are marked with sizes set to the preferred |
| @@ -284,7 +265,7 @@ TEST_F(ShortcutHelperTest, DeviceDensityFirst) { |
| EXPECT_EQ("http://foo.com/icon_x3.png", url.spec()); |
| } |
| -TEST_F(ShortcutHelperTest, DeviceDensityFallback) { |
| +TEST_F(ManifestIconSelectorTest, DeviceDensityFallback) { |
| // If there is no perfect icon but and no icon of the current display density, |
| // an icon of density 1.0 will be used. |
| std::vector<gfx::Size> sizes; |
| @@ -299,7 +280,7 @@ TEST_F(ShortcutHelperTest, DeviceDensityFallback) { |
| EXPECT_EQ("http://foo.com/icon_x1.png", url.spec()); |
| } |
| -TEST_F(ShortcutHelperTest, DoNotUseOtherDensities) { |
| +TEST_F(ManifestIconSelectorTest, DoNotUseOtherDensities) { |
| // If there are only icons of densities that are not the current display |
| // density or the default density, they are ignored. |
| std::vector<gfx::Size> sizes; |
| @@ -313,7 +294,7 @@ TEST_F(ShortcutHelperTest, DoNotUseOtherDensities) { |
| EXPECT_TRUE(url.is_empty()); |
| } |
| -TEST_F(ShortcutHelperTest, NotSquareIconsAreIgnored) { |
| +TEST_F(ManifestIconSelectorTest, NotSquareIconsAreIgnored) { |
| std::vector<gfx::Size> sizes; |
| sizes.push_back(gfx::Size(20, 2)); |
| @@ -324,8 +305,8 @@ TEST_F(ShortcutHelperTest, NotSquareIconsAreIgnored) { |
| EXPECT_TRUE(url.is_empty()); |
| } |
| -TEST_F(ShortcutHelperTest, ClosestIconToPreferred) { |
| - // This test verifies ShortcutHelper::FindBestMatchingIcon by passing |
| +TEST_F(ManifestIconSelectorTest, ClosestIconToPreferred) { |
| + // This test verifies ManifestIconSelector::FindBestMatchingIcon by passing |
| // different icon sizes and checking which one is picked. |
| // The Device Scale Factor is 1.0 and the preferred icon size is returned by |
| // GetPreferredIconSizeInDp(). |
| @@ -441,7 +422,7 @@ TEST_F(ShortcutHelperTest, ClosestIconToPreferred) { |
| } |
| } |
| -TEST_F(ShortcutHelperTest, UseAnyIfNoPreferredSize) { |
| +TEST_F(ManifestIconSelectorTest, UseAnyIfNoPreferredSize) { |
| // 'any' (ie. gfx::Size(0,0)) should be used if there is no icon of a |
| // preferred size. An icon with the current device scale factor is preferred |
| // over one with the default density. |