blob: 31e2a09dd8f68ce2b27b552be1f6783f52897f33 [file] [log] [blame]
[email protected]0f083402011-11-22 02:59:011// 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
juncaia64f769c22016-06-04 00:55:325#include "components/zoom/page_zoom.h"
[email protected]0f083402011-11-22 02:59:016#include "content/public/common/page_zoom.h"
7#include "testing/gtest/include/gtest/gtest.h"
8
wjmaclean91ddc472015-01-15 19:58:279TEST(PageTestZoom, PresetZoomFactors) {
[email protected]0f083402011-11-22 02:59:0110 // Fetch a vector of preset zoom factors, including a custom value that we
11 // already know is not going to be in the list.
12 double custom_value = 1.05; // 105%
juncaia64f769c22016-06-04 00:55:3213 std::vector<double> factors = zoom::PageZoom::PresetZoomFactors(custom_value);
[email protected]0f083402011-11-22 02:59:0114
15 // Expect at least 10 zoom factors.
16 EXPECT_GE(factors.size(), 10U);
17
18 // Expect the first and last items to match the minimum and maximum values.
19 EXPECT_DOUBLE_EQ(factors.front(), content::kMinimumZoomFactor);
20 EXPECT_DOUBLE_EQ(factors.back(), content::kMaximumZoomFactor);
21
22 // Iterate through the vector, with the following checks:
23 // 1. The values are in sorted order.
24 // 2. The custom value is exists.
25 // 3. The 100% value exists.
26 bool found_custom_value = false;
27 bool found_100_percent = false;
28 double last_value = 0;
29
30 std::vector<double>::const_iterator i;
31 for (i = factors.begin(); i != factors.end(); ++i) {
32 double factor = *i;
33 EXPECT_GT(factor, last_value);
34 if (content::ZoomValuesEqual(factor, custom_value))
35 found_custom_value = true;
36 if (content::ZoomValuesEqual(factor, 1.0))
37 found_100_percent = true;
38 last_value = factor;
39 }
40
41 EXPECT_TRUE(found_custom_value);
42 EXPECT_TRUE(found_100_percent);
43}
44
wjmaclean91ddc472015-01-15 19:58:2745TEST(PageTestZoom, PresetZoomLevels) {
[email protected]0f083402011-11-22 02:59:0146 // Fetch a vector of preset zoom levels, including a custom value that we
47 // already know is not going to be in the list.
48 double custom_value = 0.1;
juncaia64f769c22016-06-04 00:55:3249 std::vector<double> levels = zoom::PageZoom::PresetZoomLevels(custom_value);
[email protected]0f083402011-11-22 02:59:0150
51 // Expect at least 10 zoom levels.
52 EXPECT_GE(levels.size(), 10U);
53
54 // Iterate through the vector, with the following checks:
55 // 1. The values are in sorted order.
56 // 2. The custom value is exists.
57 // 3. The 100% value exists.
58 bool found_custom_value = false;
59 bool found_100_percent = false;
60 double last_value = -99;
61
62 std::vector<double>::const_iterator i;
63 for (i = levels.begin(); i != levels.end(); ++i) {
64 double level = *i;
65 EXPECT_GT(level, last_value);
66 if (content::ZoomValuesEqual(level, custom_value))
67 found_custom_value = true;
68 if (content::ZoomValuesEqual(level, 0))
69 found_100_percent = true;
70 last_value = level;
71 }
72
73 EXPECT_TRUE(found_custom_value);
74 EXPECT_TRUE(found_100_percent);
75}
76
wjmaclean91ddc472015-01-15 19:58:2777TEST(PageTestZoom, InvalidCustomFactor) {
[email protected]0f083402011-11-22 02:59:0178 double too_low = 0.01;
juncaia64f769c22016-06-04 00:55:3279 std::vector<double> factors = zoom::PageZoom::PresetZoomFactors(too_low);
[email protected]0f083402011-11-22 02:59:0180 EXPECT_FALSE(content::ZoomValuesEqual(factors.front(), too_low));
81
82 double too_high = 99.0;
juncaia64f769c22016-06-04 00:55:3283 factors = zoom::PageZoom::PresetZoomFactors(too_high);
[email protected]0f083402011-11-22 02:59:0184 EXPECT_FALSE(content::ZoomValuesEqual(factors.back(), too_high));
85}
86
wjmaclean91ddc472015-01-15 19:58:2787TEST(PageTestZoom, InvalidCustomLevel) {
[email protected]0f083402011-11-22 02:59:0188 double too_low = -99.0;
juncaia64f769c22016-06-04 00:55:3289 std::vector<double> levels = zoom::PageZoom::PresetZoomLevels(too_low);
[email protected]0f083402011-11-22 02:59:0190 EXPECT_FALSE(content::ZoomValuesEqual(levels.front(), too_low));
91
92 double too_high = 99.0;
juncaia64f769c22016-06-04 00:55:3293 levels = zoom::PageZoom::PresetZoomLevels(too_high);
[email protected]0f083402011-11-22 02:59:0194 EXPECT_FALSE(content::ZoomValuesEqual(levels.back(), too_high));
95}