[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 | |
wjmaclean | 91ddc47 | 2015-01-15 19:58:27 | [diff] [blame] | 5 | #include "components/ui/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% |
| 13 | std::vector<double> factors = |
wjmaclean | 91ddc47 | 2015-01-15 19:58:27 | [diff] [blame] | 14 | ui_zoom::PageZoom::PresetZoomFactors(custom_value); |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 15 | |
| 16 | // Expect at least 10 zoom factors. |
| 17 | EXPECT_GE(factors.size(), 10U); |
| 18 | |
| 19 | // Expect the first and last items to match the minimum and maximum values. |
| 20 | EXPECT_DOUBLE_EQ(factors.front(), content::kMinimumZoomFactor); |
| 21 | EXPECT_DOUBLE_EQ(factors.back(), content::kMaximumZoomFactor); |
| 22 | |
| 23 | // Iterate through the vector, with the following checks: |
| 24 | // 1. The values are in sorted order. |
| 25 | // 2. The custom value is exists. |
| 26 | // 3. The 100% value exists. |
| 27 | bool found_custom_value = false; |
| 28 | bool found_100_percent = false; |
| 29 | double last_value = 0; |
| 30 | |
| 31 | std::vector<double>::const_iterator i; |
| 32 | for (i = factors.begin(); i != factors.end(); ++i) { |
| 33 | double factor = *i; |
| 34 | EXPECT_GT(factor, last_value); |
| 35 | if (content::ZoomValuesEqual(factor, custom_value)) |
| 36 | found_custom_value = true; |
| 37 | if (content::ZoomValuesEqual(factor, 1.0)) |
| 38 | found_100_percent = true; |
| 39 | last_value = factor; |
| 40 | } |
| 41 | |
| 42 | EXPECT_TRUE(found_custom_value); |
| 43 | EXPECT_TRUE(found_100_percent); |
| 44 | } |
| 45 | |
wjmaclean | 91ddc47 | 2015-01-15 19:58:27 | [diff] [blame] | 46 | TEST(PageTestZoom, PresetZoomLevels) { |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 47 | // Fetch a vector of preset zoom levels, including a custom value that we |
| 48 | // already know is not going to be in the list. |
| 49 | double custom_value = 0.1; |
wjmaclean | 91ddc47 | 2015-01-15 19:58:27 | [diff] [blame] | 50 | std::vector<double> levels = |
| 51 | ui_zoom::PageZoom::PresetZoomLevels(custom_value); |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 52 | |
| 53 | // Expect at least 10 zoom levels. |
| 54 | EXPECT_GE(levels.size(), 10U); |
| 55 | |
| 56 | // Iterate through the vector, with the following checks: |
| 57 | // 1. The values are in sorted order. |
| 58 | // 2. The custom value is exists. |
| 59 | // 3. The 100% value exists. |
| 60 | bool found_custom_value = false; |
| 61 | bool found_100_percent = false; |
| 62 | double last_value = -99; |
| 63 | |
| 64 | std::vector<double>::const_iterator i; |
| 65 | for (i = levels.begin(); i != levels.end(); ++i) { |
| 66 | double level = *i; |
| 67 | EXPECT_GT(level, last_value); |
| 68 | if (content::ZoomValuesEqual(level, custom_value)) |
| 69 | found_custom_value = true; |
| 70 | if (content::ZoomValuesEqual(level, 0)) |
| 71 | found_100_percent = true; |
| 72 | last_value = level; |
| 73 | } |
| 74 | |
| 75 | EXPECT_TRUE(found_custom_value); |
| 76 | EXPECT_TRUE(found_100_percent); |
| 77 | } |
| 78 | |
wjmaclean | 91ddc47 | 2015-01-15 19:58:27 | [diff] [blame] | 79 | TEST(PageTestZoom, InvalidCustomFactor) { |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 80 | double too_low = 0.01; |
wjmaclean | 91ddc47 | 2015-01-15 19:58:27 | [diff] [blame] | 81 | std::vector<double> factors = ui_zoom::PageZoom::PresetZoomFactors(too_low); |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 82 | EXPECT_FALSE(content::ZoomValuesEqual(factors.front(), too_low)); |
| 83 | |
| 84 | double too_high = 99.0; |
wjmaclean | 91ddc47 | 2015-01-15 19:58:27 | [diff] [blame] | 85 | factors = ui_zoom::PageZoom::PresetZoomFactors(too_high); |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 86 | EXPECT_FALSE(content::ZoomValuesEqual(factors.back(), too_high)); |
| 87 | } |
| 88 | |
wjmaclean | 91ddc47 | 2015-01-15 19:58:27 | [diff] [blame] | 89 | TEST(PageTestZoom, InvalidCustomLevel) { |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 90 | double too_low = -99.0; |
wjmaclean | 91ddc47 | 2015-01-15 19:58:27 | [diff] [blame] | 91 | std::vector<double> levels = ui_zoom::PageZoom::PresetZoomLevels(too_low); |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 92 | EXPECT_FALSE(content::ZoomValuesEqual(levels.front(), too_low)); |
| 93 | |
| 94 | double too_high = 99.0; |
wjmaclean | 91ddc47 | 2015-01-15 19:58:27 | [diff] [blame] | 95 | levels = ui_zoom::PageZoom::PresetZoomLevels(too_high); |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 96 | EXPECT_FALSE(content::ZoomValuesEqual(levels.back(), too_high)); |
| 97 | } |
| 98 | |