| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/android/shortcut_helper.h" | 5 #include "chrome/browser/android/shortcut_helper.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 8 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 9 #include "content/public/browser/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
| 10 #include "ui/gfx/screen.h" | 10 #include "ui/gfx/screen.h" |
| 11 #include "ui/gfx/screen_type_delegate.h" | 11 #include "ui/gfx/screen_type_delegate.h" |
| 12 | 12 |
| 13 // A dummy implementation of gfx::Screen, since ShortcutHelper needs access to | 13 // A dummy implementation of gfx::Screen, since ShortcutHelper needs access to |
| 14 // a gfx::Display's device scale factor. | 14 // a gfx::Display's device scale factor. |
| 15 // This is inspired by web_contents_video_capture_device_unittest.cc | 15 // This is inspired by web_contents_video_capture_device_unittest.cc |
| 16 // A bug has been opened to merge all those mocks: http://crbug.com/417227 | 16 // A bug has been opened to merge all those mocks: http://crbug.com/417227 |
| 17 class FakeScreen : public gfx::Screen { | 17 class FakeScreen : public gfx::Screen { |
| 18 public: | 18 public: |
| 19 FakeScreen() : display_(0x1337, gfx::Rect(0, 0, 2560, 1440)) { | 19 FakeScreen() : display_(0x1337, gfx::Rect(0, 0, 2560, 1440)) { |
| 20 } | 20 } |
| 21 virtual ~FakeScreen() {} | 21 virtual ~FakeScreen() {} |
| 22 | 22 |
| 23 void SetDisplayDeviceScaleFactor(float device_scale_factor) { | 23 void SetDisplayDeviceScaleFactor(float device_scale_factor) { |
| 24 display_.set_device_scale_factor(device_scale_factor); | 24 display_.set_device_scale_factor(device_scale_factor); |
| 25 } | 25 } |
| 26 | 26 |
| 27 // gfx::Screen implementation (only what's needed for testing). | 27 // gfx::Screen implementation (only what's needed for testing). |
| 28 virtual bool IsDIPEnabled() OVERRIDE { return true; } | 28 virtual bool IsDIPEnabled() override { return true; } |
| 29 virtual gfx::Point GetCursorScreenPoint() OVERRIDE { return gfx::Point(); } | 29 virtual gfx::Point GetCursorScreenPoint() override { return gfx::Point(); } |
| 30 virtual gfx::NativeWindow GetWindowUnderCursor() OVERRIDE { return NULL; } | 30 virtual gfx::NativeWindow GetWindowUnderCursor() override { return NULL; } |
| 31 virtual gfx::NativeWindow GetWindowAtScreenPoint( | 31 virtual gfx::NativeWindow GetWindowAtScreenPoint( |
| 32 const gfx::Point& point) OVERRIDE { return NULL; } | 32 const gfx::Point& point) override { return NULL; } |
| 33 virtual int GetNumDisplays() const OVERRIDE { return 1; } | 33 virtual int GetNumDisplays() const override { return 1; } |
| 34 virtual std::vector<gfx::Display> GetAllDisplays() const OVERRIDE { | 34 virtual std::vector<gfx::Display> GetAllDisplays() const override { |
| 35 return std::vector<gfx::Display>(1, display_); | 35 return std::vector<gfx::Display>(1, display_); |
| 36 } | 36 } |
| 37 virtual gfx::Display GetDisplayNearestWindow( | 37 virtual gfx::Display GetDisplayNearestWindow( |
| 38 gfx::NativeView view) const OVERRIDE { | 38 gfx::NativeView view) const override { |
| 39 return display_; | 39 return display_; |
| 40 } | 40 } |
| 41 virtual gfx::Display GetDisplayNearestPoint( | 41 virtual gfx::Display GetDisplayNearestPoint( |
| 42 const gfx::Point& point) const OVERRIDE { | 42 const gfx::Point& point) const override { |
| 43 return display_; | 43 return display_; |
| 44 } | 44 } |
| 45 virtual gfx::Display GetDisplayMatching( | 45 virtual gfx::Display GetDisplayMatching( |
| 46 const gfx::Rect& match_rect) const OVERRIDE { | 46 const gfx::Rect& match_rect) const override { |
| 47 return display_; | 47 return display_; |
| 48 } | 48 } |
| 49 virtual gfx::Display GetPrimaryDisplay() const OVERRIDE { | 49 virtual gfx::Display GetPrimaryDisplay() const override { |
| 50 return display_; | 50 return display_; |
| 51 } | 51 } |
| 52 virtual void AddObserver(gfx::DisplayObserver* observer) OVERRIDE {} | 52 virtual void AddObserver(gfx::DisplayObserver* observer) override {} |
| 53 virtual void RemoveObserver(gfx::DisplayObserver* observer) OVERRIDE {} | 53 virtual void RemoveObserver(gfx::DisplayObserver* observer) override {} |
| 54 | 54 |
| 55 private: | 55 private: |
| 56 gfx::Display display_; | 56 gfx::Display display_; |
| 57 | 57 |
| 58 DISALLOW_COPY_AND_ASSIGN(FakeScreen); | 58 DISALLOW_COPY_AND_ASSIGN(FakeScreen); |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 class ShortcutHelperTest : public ChromeRenderViewHostTestHarness { | 61 class ShortcutHelperTest : public ChromeRenderViewHostTestHarness { |
| 62 protected: | 62 protected: |
| 63 ShortcutHelperTest() : shortcut_helper_(NULL) {} | 63 ShortcutHelperTest() : shortcut_helper_(NULL) {} |
| (...skipping 10 matching lines...) Expand all Loading... |
| 74 | 74 |
| 75 void ResetShorcutHelper() { | 75 void ResetShorcutHelper() { |
| 76 if (shortcut_helper_) | 76 if (shortcut_helper_) |
| 77 delete shortcut_helper_; | 77 delete shortcut_helper_; |
| 78 | 78 |
| 79 JNIEnv* env = base::android::AttachCurrentThread(); | 79 JNIEnv* env = base::android::AttachCurrentThread(); |
| 80 shortcut_helper_ = | 80 shortcut_helper_ = |
| 81 new ShortcutHelper(env, CreateShortcutHelperJava(env), web_contents()); | 81 new ShortcutHelper(env, CreateShortcutHelperJava(env), web_contents()); |
| 82 } | 82 } |
| 83 | 83 |
| 84 virtual void SetUp() OVERRIDE { | 84 virtual void SetUp() override { |
| 85 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, &fake_screen_); | 85 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, &fake_screen_); |
| 86 ASSERT_EQ(&fake_screen_, gfx::Screen::GetNativeScreen()); | 86 ASSERT_EQ(&fake_screen_, gfx::Screen::GetNativeScreen()); |
| 87 | 87 |
| 88 ChromeRenderViewHostTestHarness::SetUp(); | 88 ChromeRenderViewHostTestHarness::SetUp(); |
| 89 | 89 |
| 90 ResetShorcutHelper(); | 90 ResetShorcutHelper(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 virtual void TearDown() OVERRIDE { | 93 virtual void TearDown() override { |
| 94 delete shortcut_helper_; | 94 delete shortcut_helper_; |
| 95 shortcut_helper_ = NULL; | 95 shortcut_helper_ = NULL; |
| 96 | 96 |
| 97 ChromeRenderViewHostTestHarness::TearDown(); | 97 ChromeRenderViewHostTestHarness::TearDown(); |
| 98 | 98 |
| 99 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, NULL); | 99 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, NULL); |
| 100 } | 100 } |
| 101 | 101 |
| 102 GURL FindBestMatchingIcon(const std::vector<content::Manifest::Icon>& icons) { | 102 GURL FindBestMatchingIcon(const std::vector<content::Manifest::Icon>& icons) { |
| 103 return shortcut_helper_->FindBestMatchingIcon(icons); | 103 return shortcut_helper_->FindBestMatchingIcon(icons); |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 | 486 |
| 487 std::vector<content::Manifest::Icon> icons; | 487 std::vector<content::Manifest::Icon> icons; |
| 488 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", 1.0, sizes)); | 488 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", 1.0, sizes)); |
| 489 icons.push_back(CreateIcon("http://foo.com/icon.png", "", 3.0, sizes)); | 489 icons.push_back(CreateIcon("http://foo.com/icon.png", "", 3.0, sizes)); |
| 490 | 490 |
| 491 SetDisplayDeviceScaleFactor(3.0f); | 491 SetDisplayDeviceScaleFactor(3.0f); |
| 492 GURL url = FindBestMatchingIcon(icons); | 492 GURL url = FindBestMatchingIcon(icons); |
| 493 EXPECT_EQ("http://foo.com/icon.png", url.spec()); | 493 EXPECT_EQ("http://foo.com/icon.png", url.spec()); |
| 494 } | 494 } |
| 495 } | 495 } |
| OLD | NEW |