[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 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 | |
juncai | a64f769c2 | 2016-06-04 00:55:32 | [diff] [blame] | 5 | #include "components/zoom/page_zoom.h" |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 6 | #include "content/public/common/page_zoom.h" |
| 7 | #include "testing/gtest/include/gtest/gtest.h" |
| 8 | |
wjmaclean | 91ddc47 | 2015-01-15 19:58:27 | [diff] [blame] | 9 | TEST(PageTestZoom, PresetZoomFactors) { |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 10 | // 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% |
juncai | a64f769c2 | 2016-06-04 00:55:32 | [diff] [blame] | 13 | std::vector<double> factors = zoom::PageZoom::PresetZoomFactors(custom_value); |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 14 | |
| 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 | |
wjmaclean | 91ddc47 | 2015-01-15 19:58:27 | [diff] [blame] | 45 | TEST(PageTestZoom, PresetZoomLevels) { |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 46 | // 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; |
juncai | a64f769c2 | 2016-06-04 00:55:32 | [diff] [blame] | 49 | std::vector<double> levels = zoom::PageZoom::PresetZoomLevels(custom_value); |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 50 | |
| 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 | |
wjmaclean | 91ddc47 | 2015-01-15 19:58:27 | [diff] [blame] | 77 | TEST(PageTestZoom, InvalidCustomFactor) { |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 78 | double too_low = 0.01; |
juncai | a64f769c2 | 2016-06-04 00:55:32 | [diff] [blame] | 79 | std::vector<double> factors = zoom::PageZoom::PresetZoomFactors(too_low); |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 80 | EXPECT_FALSE(content::ZoomValuesEqual(factors.front(), too_low)); |
| 81 | |
| 82 | double too_high = 99.0; |
juncai | a64f769c2 | 2016-06-04 00:55:32 | [diff] [blame] | 83 | factors = zoom::PageZoom::PresetZoomFactors(too_high); |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 84 | EXPECT_FALSE(content::ZoomValuesEqual(factors.back(), too_high)); |
| 85 | } |
| 86 | |
wjmaclean | 91ddc47 | 2015-01-15 19:58:27 | [diff] [blame] | 87 | TEST(PageTestZoom, InvalidCustomLevel) { |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 88 | double too_low = -99.0; |
juncai | a64f769c2 | 2016-06-04 00:55:32 | [diff] [blame] | 89 | std::vector<double> levels = zoom::PageZoom::PresetZoomLevels(too_low); |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 90 | EXPECT_FALSE(content::ZoomValuesEqual(levels.front(), too_low)); |
| 91 | |
| 92 | double too_high = 99.0; |
juncai | a64f769c2 | 2016-06-04 00:55:32 | [diff] [blame] | 93 | levels = zoom::PageZoom::PresetZoomLevels(too_high); |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 94 | EXPECT_FALSE(content::ZoomValuesEqual(levels.back(), too_high)); |
| 95 | } |