summaryrefslogtreecommitdiffstats
path: root/content/browser
diff options
context:
space:
mode:
Diffstat (limited to 'content/browser')
-rw-r--r--content/browser/host_zoom_map.cc4
-rw-r--r--content/browser/host_zoom_map_unittest.cc32
-rw-r--r--content/browser/tab_contents/tab_contents.cc8
-rw-r--r--content/browser/webui/web_ui.cc9
-rw-r--r--content/browser/webui/web_ui.h3
-rw-r--r--content/browser/webui/web_ui_unittest.cc74
6 files changed, 126 insertions, 4 deletions
diff --git a/content/browser/host_zoom_map.cc b/content/browser/host_zoom_map.cc
index b827433..c36aa4e 100644
--- a/content/browser/host_zoom_map.cc
+++ b/content/browser/host_zoom_map.cc
@@ -14,6 +14,7 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
+#include "content/public/common/page_zoom.h"
#include "googleurl/src/gurl.h"
#include "net/base/net_util.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
@@ -56,7 +57,8 @@ void HostZoomMap::SetZoomLevel(std::string host, double level) {
{
base::AutoLock auto_lock(lock_);
- if (level == default_zoom_level_)
+
+ if (content::ZoomValuesEqual(level, default_zoom_level_))
host_zoom_levels_.erase(host);
else
host_zoom_levels_[host] = level;
diff --git a/content/browser/host_zoom_map_unittest.cc b/content/browser/host_zoom_map_unittest.cc
new file mode 100644
index 0000000..d151362
--- /dev/null
+++ b/content/browser/host_zoom_map_unittest.cc
@@ -0,0 +1,32 @@
+// 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/browser/host_zoom_map.h"
+
+#include "base/memory/ref_counted.h"
+#include "base/message_loop.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/test/test_browser_thread.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+class HostZoomMapTest : public testing::Test {
+ public:
+ HostZoomMapTest() : ui_thread_(content::BrowserThread::UI, &message_loop_) {
+ }
+
+ protected:
+ MessageLoop message_loop_;
+ content::TestBrowserThread ui_thread_;
+};
+
+TEST_F(HostZoomMapTest, GetSetZoomLevel) {
+ scoped_refptr<HostZoomMap> host_zoom_map = new HostZoomMap;
+
+ double zoomed = 2.5;
+ host_zoom_map->SetZoomLevel("zoomed.com", zoomed);
+
+ EXPECT_DOUBLE_EQ(host_zoom_map->GetZoomLevel("normal.com"), 0);
+ EXPECT_DOUBLE_EQ(host_zoom_map->GetZoomLevel("zoomed.com"), zoomed);
+}
+
diff --git a/content/browser/tab_contents/tab_contents.cc b/content/browser/tab_contents/tab_contents.cc
index eb1f934..5fe45a9 100644
--- a/content/browser/tab_contents/tab_contents.cc
+++ b/content/browser/tab_contents/tab_contents.cc
@@ -197,9 +197,9 @@ TabContents::TabContents(content::BrowserContext* browser_context,
opener_web_ui_type_(WebUI::kNoWebUI),
closed_by_user_gesture_(false),
minimum_zoom_percent_(
- static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)),
+ static_cast<int>(content::kMinimumZoomFactor * 100)),
maximum_zoom_percent_(
- static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)),
+ static_cast<int>(content::kMaximumZoomFactor * 100)),
temporary_zoom_settings_(false),
content_restrictions_(0),
view_type_(content::VIEW_TYPE_TAB_CONTENTS) {
@@ -862,8 +862,10 @@ double TabContents::GetZoomLevel() const {
int TabContents::GetZoomPercent(bool* enable_increment,
bool* enable_decrement) {
*enable_decrement = *enable_increment = false;
+ // Calculate the zoom percent from the factor. Round up to the nearest whole
+ // number.
int percent = static_cast<int>(
- WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100);
+ WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
*enable_decrement = percent > minimum_zoom_percent_;
*enable_increment = percent < maximum_zoom_percent_;
return percent;
diff --git a/content/browser/webui/web_ui.cc b/content/browser/webui/web_ui.cc
index 5febef8..38e9839 100644
--- a/content/browser/webui/web_ui.cc
+++ b/content/browser/webui/web_ui.cc
@@ -228,6 +228,15 @@ bool WebUIMessageHandler::ExtractIntegerValue(const ListValue* value,
return false;
}
+bool WebUIMessageHandler::ExtractDoubleValue(const ListValue* value,
+ double* out_value) {
+ std::string string_value;
+ if (value->GetString(0, &string_value))
+ return base::StringToDouble(string_value, out_value);
+ NOTREACHED();
+ return false;
+}
+
string16 WebUIMessageHandler::ExtractStringValue(const ListValue* value) {
string16 string16_value;
if (value->GetString(0, &string16_value))
diff --git a/content/browser/webui/web_ui.h b/content/browser/webui/web_ui.h
index 998513f..5cba59f 100644
--- a/content/browser/webui/web_ui.h
+++ b/content/browser/webui/web_ui.h
@@ -219,6 +219,9 @@ class CONTENT_EXPORT WebUIMessageHandler {
// Extract an integer value from a list Value.
bool ExtractIntegerValue(const base::ListValue* value, int* out_int);
+ // Extract a floating point (double) value from a list Value.
+ bool ExtractDoubleValue(const base::ListValue* value, double* out_value);
+
// Extract a string value from a list Value.
string16 ExtractStringValue(const base::ListValue* value);
diff --git a/content/browser/webui/web_ui_unittest.cc b/content/browser/webui/web_ui_unittest.cc
new file mode 100644
index 0000000..93e597f
--- /dev/null
+++ b/content/browser/webui/web_ui_unittest.cc
@@ -0,0 +1,74 @@
+// 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/browser/webui/web_ui.h"
+
+#include "base/string16.h"
+#include "base/values.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+class TestWebUIMessageHandler : public WebUIMessageHandler {
+ public:
+ TestWebUIMessageHandler() {}
+ virtual ~TestWebUIMessageHandler() {}
+
+ protected:
+ virtual void RegisterMessages() {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TestWebUIMessageHandler);
+};
+
+TEST(WebUIMessageHandlerTest, ExtractIntegerValue) {
+ TestWebUIMessageHandler handler;
+
+ ListValue list;
+ int value, zero_value = 0, neg_value = -1234, pos_value = 1234;
+
+ list.Append(Value::CreateIntegerValue(zero_value));
+ EXPECT_TRUE(handler.ExtractIntegerValue(&list, &value));
+ EXPECT_EQ(value, zero_value);
+ list.Clear();
+
+ list.Append(Value::CreateIntegerValue(neg_value));
+ EXPECT_TRUE(handler.ExtractIntegerValue(&list, &value));
+ EXPECT_EQ(value, neg_value);
+ list.Clear();
+
+ list.Append(Value::CreateIntegerValue(pos_value));
+ EXPECT_TRUE(handler.ExtractIntegerValue(&list, &value));
+ EXPECT_EQ(value, pos_value);
+}
+
+TEST(WebUIMessageHandlerTest, ExtractDoubleValue) {
+ TestWebUIMessageHandler handler;
+
+ ListValue list;
+ double value, zero_value = 0.0, neg_value = -1234.5, pos_value = 1234.5;
+
+ list.Append(Value::CreateDoubleValue(zero_value));
+ EXPECT_TRUE(handler.ExtractDoubleValue(&list, &value));
+ EXPECT_EQ(value, zero_value);
+ list.Clear();
+
+ list.Append(Value::CreateDoubleValue(neg_value));
+ EXPECT_TRUE(handler.ExtractDoubleValue(&list, &value));
+ EXPECT_EQ(value, neg_value);
+ list.Clear();
+
+ list.Append(Value::CreateDoubleValue(pos_value));
+ EXPECT_TRUE(handler.ExtractDoubleValue(&list, &value));
+ EXPECT_EQ(value, pos_value);
+}
+
+TEST(WebUIMessageHandlerTest, ExtractStringValue) {
+ TestWebUIMessageHandler handler;
+
+ ListValue list;
+ string16 in_string = "The facts, though interesting, are irrelevant."
+ list.Append(Value::CreateStringValue(string));
+ string16 out_string = handler.ExtractStringValue(&list);
+ EXPECT_STREQ(in_string.c_str(), out_string.c_str());
+}
+