| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/browser/host_zoom_map_impl.h" | 5 #include "content/browser/host_zoom_map_impl.h" |
| 6 | 6 |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 10 #include "content/public/test/test_browser_thread.h" | 10 #include "content/public/test/test_browser_thread.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 namespace content { | 13 namespace content { |
| 14 | 14 |
| 15 class HostZoomMapTest : public testing::Test { | 15 class HostZoomMapTest : public testing::Test { |
| 16 public: | 16 public: |
| 17 HostZoomMapTest() : ui_thread_(BrowserThread::UI, &message_loop_) { | 17 HostZoomMapTest() : ui_thread_(BrowserThread::UI, &message_loop_) { |
| 18 } | 18 } |
| 19 | 19 |
| 20 protected: | 20 protected: |
| 21 base::MessageLoop message_loop_; | 21 base::MessageLoop message_loop_; |
| 22 TestBrowserThread ui_thread_; | 22 TestBrowserThread ui_thread_; |
| 23 }; | 23 }; |
| 24 | 24 |
| 25 TEST_F(HostZoomMapTest, GetSetZoomLevel) { | 25 TEST_F(HostZoomMapTest, GetSetZoomLevel) { |
| 26 HostZoomMapImpl host_zoom_map; | 26 HostZoomMapImpl host_zoom_map(0.0); |
| 27 | 27 |
| 28 double zoomed = 2.5; | 28 double zoomed = 2.5; |
| 29 host_zoom_map.SetZoomLevelForHost("zoomed.com", zoomed); | 29 host_zoom_map.SetZoomLevelForHost("zoomed.com", zoomed); |
| 30 | 30 |
| 31 EXPECT_DOUBLE_EQ(0, | 31 EXPECT_DOUBLE_EQ(0, |
| 32 host_zoom_map.GetZoomLevelForHostAndScheme("http", "normal.com")); | 32 host_zoom_map.GetZoomLevelForHostAndScheme("http", "normal.com")); |
| 33 EXPECT_DOUBLE_EQ(zoomed, | 33 EXPECT_DOUBLE_EQ(zoomed, |
| 34 host_zoom_map.GetZoomLevelForHostAndScheme("http", "zoomed.com")); | 34 host_zoom_map.GetZoomLevelForHostAndScheme("http", "zoomed.com")); |
| 35 } | 35 } |
| 36 | 36 |
| 37 TEST_F(HostZoomMapTest, GetSetZoomLevelWithScheme) { | 37 TEST_F(HostZoomMapTest, GetSetZoomLevelWithScheme) { |
| 38 HostZoomMapImpl host_zoom_map; | 38 HostZoomMapImpl host_zoom_map(0.0); |
| 39 | 39 |
| 40 double zoomed = 2.5; | 40 double zoomed = 2.5; |
| 41 double default_zoom = 1.5; | 41 double default_zoom = 1.5; |
| 42 | 42 |
| 43 host_zoom_map.SetZoomLevelForHostAndScheme("chrome", "login", 0); | 43 host_zoom_map.SetZoomLevelForHostAndScheme("chrome", "login", 0); |
| 44 | 44 |
| 45 host_zoom_map.SetDefaultZoomLevel(default_zoom); | 45 host_zoom_map.SetDefaultZoomLevel(default_zoom); |
| 46 | 46 |
| 47 EXPECT_DOUBLE_EQ(0, | 47 EXPECT_DOUBLE_EQ(0, |
| 48 host_zoom_map.GetZoomLevelForHostAndScheme("chrome", "login")); | 48 host_zoom_map.GetZoomLevelForHostAndScheme("chrome", "login")); |
| 49 EXPECT_DOUBLE_EQ(default_zoom, | 49 EXPECT_DOUBLE_EQ(default_zoom, |
| 50 host_zoom_map.GetZoomLevelForHostAndScheme("http", "login")); | 50 host_zoom_map.GetZoomLevelForHostAndScheme("http", "login")); |
| 51 | 51 |
| 52 host_zoom_map.SetZoomLevelForHost("login", zoomed); | 52 host_zoom_map.SetZoomLevelForHost("login", zoomed); |
| 53 | 53 |
| 54 EXPECT_DOUBLE_EQ(0, | 54 EXPECT_DOUBLE_EQ(0, |
| 55 host_zoom_map.GetZoomLevelForHostAndScheme("chrome", "login")); | 55 host_zoom_map.GetZoomLevelForHostAndScheme("chrome", "login")); |
| 56 EXPECT_DOUBLE_EQ(zoomed, | 56 EXPECT_DOUBLE_EQ(zoomed, |
| 57 host_zoom_map.GetZoomLevelForHostAndScheme("http", "login")); | 57 host_zoom_map.GetZoomLevelForHostAndScheme("http", "login")); |
| 58 } | 58 } |
| 59 | 59 |
| 60 TEST_F(HostZoomMapTest, GetAllZoomLevels) { | 60 TEST_F(HostZoomMapTest, GetAllZoomLevels) { |
| 61 HostZoomMapImpl host_zoom_map; | 61 HostZoomMapImpl host_zoom_map(0.0); |
| 62 | 62 |
| 63 double zoomed = 2.5; | 63 double zoomed = 2.5; |
| 64 host_zoom_map.SetZoomLevelForHost("zoomed.com", zoomed); | 64 host_zoom_map.SetZoomLevelForHost("zoomed.com", zoomed); |
| 65 host_zoom_map.SetZoomLevelForHostAndScheme("https", "zoomed.com", zoomed); | 65 host_zoom_map.SetZoomLevelForHostAndScheme("https", "zoomed.com", zoomed); |
| 66 host_zoom_map.SetZoomLevelForHostAndScheme("chrome", "login", zoomed); | 66 host_zoom_map.SetZoomLevelForHostAndScheme("chrome", "login", zoomed); |
| 67 | 67 |
| 68 HostZoomMap::ZoomLevelVector levels = host_zoom_map.GetAllZoomLevels(); | 68 HostZoomMap::ZoomLevelVector levels = host_zoom_map.GetAllZoomLevels(); |
| 69 HostZoomMap::ZoomLevelChange expected[] = { | 69 HostZoomMap::ZoomLevelChange expected[] = { |
| 70 {HostZoomMap::ZOOM_CHANGED_FOR_HOST, "zoomed.com", std::string(), zoomed}, | 70 {HostZoomMap::ZOOM_CHANGED_FOR_HOST, "zoomed.com", std::string(), zoomed}, |
| 71 {HostZoomMap::ZOOM_CHANGED_FOR_SCHEME_AND_HOST, "login", "chrome", | 71 {HostZoomMap::ZOOM_CHANGED_FOR_SCHEME_AND_HOST, "login", "chrome", |
| 72 zoomed}, | 72 zoomed}, |
| 73 {HostZoomMap::ZOOM_CHANGED_FOR_SCHEME_AND_HOST, "zoomed.com", "https", | 73 {HostZoomMap::ZOOM_CHANGED_FOR_SCHEME_AND_HOST, "zoomed.com", "https", |
| 74 zoomed}, }; | 74 zoomed}, }; |
| 75 ASSERT_EQ(arraysize(expected), levels.size()); | 75 ASSERT_EQ(arraysize(expected), levels.size()); |
| 76 for (size_t i = 0; i < arraysize(expected); ++i) { | 76 for (size_t i = 0; i < arraysize(expected); ++i) { |
| 77 SCOPED_TRACE(testing::Message() << "levels[" << i << "]"); | 77 SCOPED_TRACE(testing::Message() << "levels[" << i << "]"); |
| 78 EXPECT_EQ(expected[i].mode, levels[i].mode); | 78 EXPECT_EQ(expected[i].mode, levels[i].mode); |
| 79 EXPECT_EQ(expected[i].scheme, levels[i].scheme); | 79 EXPECT_EQ(expected[i].scheme, levels[i].scheme); |
| 80 EXPECT_EQ(expected[i].host, levels[i].host); | 80 EXPECT_EQ(expected[i].host, levels[i].host); |
| 81 EXPECT_EQ(expected[i].zoom_level, levels[i].zoom_level); | 81 EXPECT_EQ(expected[i].zoom_level, levels[i].zoom_level); |
| 82 } | 82 } |
| 83 } | 83 } |
| 84 | 84 |
| 85 } // namespace content | 85 } // namespace content |
| OLD | NEW |