Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: content/public/common/page_zoom_unittest.cc

Issue 8528011: Page zoom improvements (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Tweak, Tweak Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/public/common/page_zoom.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 TEST(PageZoomTest, ZoomValuesEqual) {
10 // Test two identical values.
11 EXPECT_TRUE(content::ZoomValuesEqual(1.5, 1.5));
12
13 // Test two values that are close enough to be considered equal.
14 EXPECT_TRUE(content::ZoomValuesEqual(1.5, 1.49999999));
15
16 // Test two values that are close, but should not be considered equal.
17 EXPECT_FALSE(content::ZoomValuesEqual(1.5, 1.4));
18 }
19
20 TEST(PageZoomTest, PresetZoomFactors) {
21 // Fetch a vector of preset zoom factors, including a custom value that we
22 // already know is not going to be in the list.
23 double custom_value = 1.05; // 105%
24 std::vector<double> factors = content::PresetZoomFactors(custom_value);
25
26 // Expect at least 10 zoom factors.
27 EXPECT_GE(factors.size(), 10U);
28
29 // Expect the first and last items to match the minimum and maximum values.
30 EXPECT_DOUBLE_EQ(factors.front(), content::kMinimumZoomFactor);
31 EXPECT_DOUBLE_EQ(factors.back(), content::kMaximumZoomFactor);
32
33 // Iterate through the vector, with the following checks:
34 // 1. The values are in sorted order.
35 // 2. The custom value is exists.
36 // 3. The 100% value exists.
37 bool found_custom_value = false;
38 bool found_100_percent = false;
39 double last_value = 0;
40
41 std::vector<double>::const_iterator i;
42 for (i = factors.begin(); i != factors.end(); ++i) {
43 double factor = *i;
44 EXPECT_GT(factor, last_value);
45 if (content::ZoomValuesEqual(factor, custom_value))
46 found_custom_value = true;
47 if (content::ZoomValuesEqual(factor, 1.0))
48 found_100_percent = true;
49 last_value = factor;
50 }
51
52 EXPECT_TRUE(found_custom_value);
53 EXPECT_TRUE(found_100_percent);
54 }
55
56 TEST(PageZoomTest, PresetZoomLevels) {
57 // Fetch a vector of preset zoom levels, including a custom value that we
58 // already know is not going to be in the list.
59 double custom_value = 0.1;
60 std::vector<double> levels = content::PresetZoomLevels(custom_value);
61
62 // Expect at least 10 zoom levels.
63 EXPECT_GE(levels.size(), 10U);
64
65 // Iterate through the vector, with the following checks:
66 // 1. The values are in sorted order.
67 // 2. The custom value is exists.
68 // 3. The 100% value exists.
69 bool found_custom_value = false;
70 bool found_100_percent = false;
71 double last_value = -99;
72
73 std::vector<double>::const_iterator i;
74 for (i = levels.begin(); i != levels.end(); ++i) {
75 double level = *i;
76 EXPECT_GT(level, last_value);
77 if (content::ZoomValuesEqual(level, custom_value))
78 found_custom_value = true;
79 if (content::ZoomValuesEqual(level, 0))
80 found_100_percent = true;
81 last_value = level;
82 }
83
84 EXPECT_TRUE(found_custom_value);
85 EXPECT_TRUE(found_100_percent);
86 }
87
88 TEST(PageZoomTest, InvalidCustomFactor) {
89 double too_low = 0.01;
90 std::vector<double> factors = content::PresetZoomFactors(too_low);
91 EXPECT_FALSE(content::ZoomValuesEqual(factors.front(), too_low));
92
93 double too_high = 99.0;
94 factors = content::PresetZoomFactors(too_high);
95 EXPECT_FALSE(content::ZoomValuesEqual(factors.back(), too_high));
96 }
97
98 TEST(PageZoomTest, InvalidCustomLevel) {
99 double too_low = -99.0;
100 std::vector<double> levels = content::PresetZoomLevels(too_low);
101 EXPECT_FALSE(content::ZoomValuesEqual(levels.front(), too_low));
102
103 double too_high = 99.0;
104 levels = content::PresetZoomLevels(too_high);
105 EXPECT_FALSE(content::ZoomValuesEqual(levels.back(), too_high));
106 }
107
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698