OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "webkit/glue/webkit_glue.h" | 5 #include "webkit/glue/webkit_glue.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
11 #include "googleurl/src/gurl.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "third_party/skia/include/core/SkBitmap.h" | 12 #include "third_party/skia/include/core/SkBitmap.h" |
14 #include "webkit/glue/webkit_glue.h" | |
15 #include "webkit/glue/webkitplatformsupport_impl.h" | 13 #include "webkit/glue/webkitplatformsupport_impl.h" |
16 #include "webkit/tools/test_shell/test_shell_test.h" | |
17 | 14 |
18 namespace { | 15 namespace { |
19 | 16 |
20 TEST(WebkitGlueTest, DecodeImageFail) { | 17 TEST(WebkitGlueTest, DecodeImageFail) { |
21 std::string data("not an image"); | 18 std::string data("not an image"); |
22 SkBitmap image; | 19 SkBitmap image; |
23 EXPECT_FALSE(webkit_glue::DecodeImage(data, &image)); | 20 EXPECT_FALSE(webkit_glue::DecodeImage(data, &image)); |
24 EXPECT_TRUE(image.isNull()); | 21 EXPECT_TRUE(image.isNull()); |
25 } | 22 } |
26 | 23 |
27 TEST(WebkitGlueTest, DecodeImage) { | 24 TEST(WebkitGlueTest, DecodeImage) { |
28 std::string data("GIF87a\x02\x00\x02\x00\xa1\x04\x00\x00\x00\x00\x00\x00\xff" | 25 std::string data("GIF87a\x02\x00\x02\x00\xa1\x04\x00\x00\x00\x00\x00\x00\xff" |
29 "\xff\x00\x00\x00\xff\x00,\x00\x00\x00\x00\x02\x00\x02\x00" | 26 "\xff\x00\x00\x00\xff\x00,\x00\x00\x00\x00\x02\x00\x02\x00" |
30 "\x00\x02\x03\x84\x16\x05\x00;", 42); | 27 "\x00\x02\x03\x84\x16\x05\x00;", 42); |
31 EXPECT_EQ(42u, data.size()); | 28 EXPECT_EQ(42u, data.size()); |
32 SkBitmap image; | 29 SkBitmap image; |
33 EXPECT_TRUE(webkit_glue::DecodeImage(data, &image)); | 30 EXPECT_TRUE(webkit_glue::DecodeImage(data, &image)); |
34 EXPECT_FALSE(image.isNull()); | 31 EXPECT_FALSE(image.isNull()); |
35 EXPECT_EQ(2, image.width()); | 32 EXPECT_EQ(2, image.width()); |
36 EXPECT_EQ(2, image.height()); | 33 EXPECT_EQ(2, image.height()); |
37 EXPECT_EQ(SkBitmap::kARGB_8888_Config, image.config()); | 34 EXPECT_EQ(SkBitmap::kARGB_8888_Config, image.config()); |
38 image.lockPixels(); | 35 image.lockPixels(); |
39 EXPECT_EQ(SK_ColorBLACK, *image.getAddr32(0, 0)); | 36 EXPECT_EQ(SK_ColorBLACK, *image.getAddr32(0, 0)); |
40 EXPECT_EQ(SK_ColorRED, *image.getAddr32(1, 0)); | 37 EXPECT_EQ(SK_ColorRED, *image.getAddr32(1, 0)); |
41 EXPECT_EQ(SK_ColorGREEN, *image.getAddr32(0, 1)); | 38 EXPECT_EQ(SK_ColorGREEN, *image.getAddr32(0, 1)); |
42 EXPECT_EQ(SK_ColorBLUE, *image.getAddr32(1, 1)); | 39 EXPECT_EQ(SK_ColorBLUE, *image.getAddr32(1, 1)); |
43 image.unlockPixels(); | 40 image.unlockPixels(); |
44 } | 41 } |
45 | 42 |
46 class WebkitGlueUserAgentTest : public TestShellTest { | |
47 }; | |
48 | |
49 bool IsSpoofedUserAgent(const std::string& user_agent) { | |
50 return user_agent.find("TestShell") == std::string::npos; | |
51 } | |
52 | |
53 TEST_F(WebkitGlueUserAgentTest, UserAgentSpoofingHack) { | |
54 enum Platform { | |
55 NONE = 0, | |
56 MACOSX = 1, | |
57 WIN = 2, | |
58 OTHER = 4, | |
59 }; | |
60 | |
61 struct Expected { | |
62 const char* url; | |
63 int os_mask; | |
64 }; | |
65 | |
66 Expected expected[] = { | |
67 { "http://wwww.google.com", NONE }, | |
68 { "http://www.microsoft.com/getsilverlight", MACOSX }, | |
69 { "http://headlines.yahoo.co.jp/videonews/", MACOSX | WIN }, | |
70 { "http://downloads.yahoo.co.jp/docs/silverlight/", MACOSX }, | |
71 { "http://gyao.yahoo.co.jp/", MACOSX }, | |
72 { "http://weather.yahoo.co.jp/weather/zoomradar/", WIN }, | |
73 { "http://promotion.shopping.yahoo.co.jp/", WIN }, | |
74 { "http://pokemon.kids.yahoo.co.jp", WIN }, | |
75 }; | |
76 #if defined(OS_MACOSX) | |
77 int os_bit = MACOSX; | |
78 #elif defined(OS_WIN) | |
79 int os_bit = WIN; | |
80 #else | |
81 int os_bit = OTHER; | |
82 #endif | |
83 | |
84 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(expected); ++i) { | |
85 EXPECT_EQ((expected[i].os_mask & os_bit) != 0, | |
86 IsSpoofedUserAgent( | |
87 webkit_glue::GetUserAgent(GURL(expected[i].url)))); | |
88 } | |
89 } | |
90 | |
91 // Derives WebKitPlatformSupportImpl for testing shared timers. | 43 // Derives WebKitPlatformSupportImpl for testing shared timers. |
92 class TestWebKitPlatformSupport | 44 class TestWebKitPlatformSupport |
93 : public webkit_glue::WebKitPlatformSupportImpl { | 45 : public webkit_glue::WebKitPlatformSupportImpl { |
94 public: | 46 public: |
95 TestWebKitPlatformSupport() : mock_monotonically_increasing_time_(0) { | 47 TestWebKitPlatformSupport() : mock_monotonically_increasing_time_(0) { |
96 } | 48 } |
97 | 49 |
98 // WebKitPlatformSupportImpl implementation | 50 // WebKitPlatformSupportImpl implementation |
99 virtual string16 GetLocalizedString(int) OVERRIDE { | 51 virtual string16 GetLocalizedString(int) OVERRIDE { |
100 return string16(); | 52 return string16(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 // Set a mock time after 1 second to simulate timers suspended for 1 second. | 110 // Set a mock time after 1 second to simulate timers suspended for 1 second. |
159 double new_time = base::Time::Now().ToDoubleT() + 1; | 111 double new_time = base::Time::Now().ToDoubleT() + 1; |
160 platform_support.set_mock_monotonically_increasing_time(new_time); | 112 platform_support.set_mock_monotonically_increasing_time(new_time); |
161 // Resume timers so that the timer set above will be set again to fire | 113 // Resume timers so that the timer set above will be set again to fire |
162 // immediately. | 114 // immediately. |
163 platform_support.ResumeSharedTimer(); | 115 platform_support.ResumeSharedTimer(); |
164 EXPECT_TRUE(base::TimeDelta() == platform_support.shared_timer_delay()); | 116 EXPECT_TRUE(base::TimeDelta() == platform_support.shared_timer_delay()); |
165 } | 117 } |
166 | 118 |
167 } // namespace | 119 } // namespace |
OLD | NEW |