| Index: content/public/common/page_zoom_unittest.cc
|
| ===================================================================
|
| --- content/public/common/page_zoom_unittest.cc (revision 0)
|
| +++ content/public/common/page_zoom_unittest.cc (revision 0)
|
| @@ -0,0 +1,107 @@
|
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "content/public/common/page_zoom.h"
|
| +
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +TEST(PageZoomTest, ZoomValuesEqual) {
|
| + // Test two identical values.
|
| + EXPECT_TRUE(content::ZoomValuesEqual(1.5, 1.5));
|
| +
|
| + // Test two values that are close enough to be considered equal.
|
| + EXPECT_TRUE(content::ZoomValuesEqual(1.5, 1.49999999));
|
| +
|
| + // Test two values that are close, but should not be considered equal.
|
| + EXPECT_FALSE(content::ZoomValuesEqual(1.5, 1.4));
|
| +}
|
| +
|
| +TEST(PageZoomTest, PresetZoomFactors) {
|
| + // Fetch a vector of preset zoom factors, including a custom value that we
|
| + // already know is not going to be in the list.
|
| + double custom_value = 1.05; // 105%
|
| + std::vector<double> factors = content::PresetZoomFactors(custom_value);
|
| +
|
| + // Expect at least 10 zoom factors.
|
| + EXPECT_GE(factors.size(), 10U);
|
| +
|
| + // Expect the first and last items to match the minimum and maximum values.
|
| + EXPECT_DOUBLE_EQ(factors.front(), content::kMinimumZoomFactor);
|
| + EXPECT_DOUBLE_EQ(factors.back(), content::kMaximumZoomFactor);
|
| +
|
| + // Iterate through the vector, with the following checks:
|
| + // 1. The values are in sorted order.
|
| + // 2. The custom value is exists.
|
| + // 3. The 100% value exists.
|
| + bool found_custom_value = false;
|
| + bool found_100_percent = false;
|
| + double last_value = 0;
|
| +
|
| + std::vector<double>::const_iterator i;
|
| + for (i = factors.begin(); i != factors.end(); ++i) {
|
| + double factor = *i;
|
| + EXPECT_GT(factor, last_value);
|
| + if (content::ZoomValuesEqual(factor, custom_value))
|
| + found_custom_value = true;
|
| + if (content::ZoomValuesEqual(factor, 1.0))
|
| + found_100_percent = true;
|
| + last_value = factor;
|
| + }
|
| +
|
| + EXPECT_TRUE(found_custom_value);
|
| + EXPECT_TRUE(found_100_percent);
|
| +}
|
| +
|
| +TEST(PageZoomTest, PresetZoomLevels) {
|
| + // Fetch a vector of preset zoom levels, including a custom value that we
|
| + // already know is not going to be in the list.
|
| + double custom_value = 0.1;
|
| + std::vector<double> levels = content::PresetZoomLevels(custom_value);
|
| +
|
| + // Expect at least 10 zoom levels.
|
| + EXPECT_GE(levels.size(), 10U);
|
| +
|
| + // Iterate through the vector, with the following checks:
|
| + // 1. The values are in sorted order.
|
| + // 2. The custom value is exists.
|
| + // 3. The 100% value exists.
|
| + bool found_custom_value = false;
|
| + bool found_100_percent = false;
|
| + double last_value = -99;
|
| +
|
| + std::vector<double>::const_iterator i;
|
| + for (i = levels.begin(); i != levels.end(); ++i) {
|
| + double level = *i;
|
| + EXPECT_GT(level, last_value);
|
| + if (content::ZoomValuesEqual(level, custom_value))
|
| + found_custom_value = true;
|
| + if (content::ZoomValuesEqual(level, 0))
|
| + found_100_percent = true;
|
| + last_value = level;
|
| + }
|
| +
|
| + EXPECT_TRUE(found_custom_value);
|
| + EXPECT_TRUE(found_100_percent);
|
| +}
|
| +
|
| +TEST(PageZoomTest, InvalidCustomFactor) {
|
| + double too_low = 0.01;
|
| + std::vector<double> factors = content::PresetZoomFactors(too_low);
|
| + EXPECT_FALSE(content::ZoomValuesEqual(factors.front(), too_low));
|
| +
|
| + double too_high = 99.0;
|
| + factors = content::PresetZoomFactors(too_high);
|
| + EXPECT_FALSE(content::ZoomValuesEqual(factors.back(), too_high));
|
| +}
|
| +
|
| +TEST(PageZoomTest, InvalidCustomLevel) {
|
| + double too_low = -99.0;
|
| + std::vector<double> levels = content::PresetZoomLevels(too_low);
|
| + EXPECT_FALSE(content::ZoomValuesEqual(levels.front(), too_low));
|
| +
|
| + double too_high = 99.0;
|
| + levels = content::PresetZoomLevels(too_high);
|
| + EXPECT_FALSE(content::ZoomValuesEqual(levels.back(), too_high));
|
| +}
|
| +
|
|
|
| Property changes on: content/public/common/page_zoom_unittest.cc
|
| ___________________________________________________________________
|
| Added: svn:eol-style
|
| + LF
|
|
|
|
|