| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/utf_string_conversions.h" | 5 #include "base/utf_string_conversions.h" |
| 6 #include "base/time.h" | 6 #include "base/time.h" |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "chrome/browser/content_settings/host_content_settings_map.h" | 8 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/renderer_host/render_view_host.h" | 10 #include "chrome/browser/renderer_host/render_view_host.h" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 EXPECT_EQ(Value::TYPE_INTEGER, observer.value()->GetType()); | 110 EXPECT_EQ(Value::TYPE_INTEGER, observer.value()->GetType()); |
| 111 int int_value; | 111 int int_value; |
| 112 EXPECT_TRUE(observer.value()->GetAsInteger(&int_value)); | 112 EXPECT_TRUE(observer.value()->GetAsInteger(&int_value)); |
| 113 EXPECT_EQ(42, int_value); | 113 EXPECT_EQ(42, int_value); |
| 114 } | 114 } |
| 115 | 115 |
| 116 // Try a floating point number. | 116 // Try a floating point number. |
| 117 { | 117 { |
| 118 ExecuteNotificationObserver observer; | 118 ExecuteNotificationObserver observer; |
| 119 ExecuteJavascriptAndGetValue("42.2;", &observer); | 119 ExecuteJavascriptAndGetValue("42.2;", &observer); |
| 120 EXPECT_EQ(Value::TYPE_REAL, observer.value()->GetType()); | 120 EXPECT_EQ(Value::TYPE_DOUBLE, observer.value()->GetType()); |
| 121 double double_value; | 121 double double_value; |
| 122 EXPECT_TRUE(observer.value()->GetAsReal(&double_value)); | 122 EXPECT_TRUE(observer.value()->GetAsDouble(&double_value)); |
| 123 EXPECT_EQ(42.2, double_value); | 123 EXPECT_EQ(42.2, double_value); |
| 124 } | 124 } |
| 125 | 125 |
| 126 // Let's check out string. | 126 // Let's check out string. |
| 127 { | 127 { |
| 128 ExecuteNotificationObserver observer; | 128 ExecuteNotificationObserver observer; |
| 129 ExecuteJavascriptAndGetValue("\"something completely different\";", | 129 ExecuteJavascriptAndGetValue("\"something completely different\";", |
| 130 &observer); | 130 &observer); |
| 131 EXPECT_EQ(Value::TYPE_STRING, observer.value()->GetType()); | 131 EXPECT_EQ(Value::TYPE_STRING, observer.value()->GetType()); |
| 132 std::string string_value; | 132 std::string string_value; |
| 133 EXPECT_TRUE(observer.value()->GetAsString(&string_value)); | 133 EXPECT_TRUE(observer.value()->GetAsString(&string_value)); |
| 134 EXPECT_EQ(std::string("something completely different"), string_value); | 134 EXPECT_EQ(std::string("something completely different"), string_value); |
| 135 } | 135 } |
| 136 | 136 |
| 137 // Regular expressions might be fun. | 137 // Regular expressions might be fun. |
| 138 { | 138 { |
| 139 ExecuteNotificationObserver observer; | 139 ExecuteNotificationObserver observer; |
| 140 ExecuteJavascriptAndGetValue("/finder.*foo/g;", &observer); | 140 ExecuteJavascriptAndGetValue("/finder.*foo/g;", &observer); |
| 141 EXPECT_EQ(Value::TYPE_STRING, observer.value()->GetType()); | 141 EXPECT_EQ(Value::TYPE_STRING, observer.value()->GetType()); |
| 142 std::string string_value; | 142 std::string string_value; |
| 143 EXPECT_TRUE(observer.value()->GetAsString(&string_value)); | 143 EXPECT_TRUE(observer.value()->GetAsString(&string_value)); |
| 144 EXPECT_EQ(std::string("/finder.*foo/g"), string_value); | 144 EXPECT_EQ(std::string("/finder.*foo/g"), string_value); |
| 145 } | 145 } |
| 146 | 146 |
| 147 // Let's test some date conversions. First up, epoch. Can't use 0 because | 147 // Let's test some date conversions. First up, epoch. Can't use 0 because |
| 148 // that means uninitialized, so use the next best thing. | 148 // that means uninitialized, so use the next best thing. |
| 149 { | 149 { |
| 150 ExecuteNotificationObserver observer; | 150 ExecuteNotificationObserver observer; |
| 151 ExecuteJavascriptAndGetValue("new Date(1);", &observer); | 151 ExecuteJavascriptAndGetValue("new Date(1);", &observer); |
| 152 EXPECT_EQ(Value::TYPE_REAL, observer.value()->GetType()); | 152 EXPECT_EQ(Value::TYPE_DOUBLE, observer.value()->GetType()); |
| 153 double date_seconds; | 153 double date_seconds; |
| 154 EXPECT_TRUE(observer.value()->GetAsReal(&date_seconds)); | 154 EXPECT_TRUE(observer.value()->GetAsDouble(&date_seconds)); |
| 155 | 155 |
| 156 base::Time time = base::Time::FromDoubleT(date_seconds); | 156 base::Time time = base::Time::FromDoubleT(date_seconds); |
| 157 | 157 |
| 158 base::Time::Exploded time_exploded; | 158 base::Time::Exploded time_exploded; |
| 159 time.UTCExplode(&time_exploded); | 159 time.UTCExplode(&time_exploded); |
| 160 EXPECT_EQ(1970, time_exploded.year); | 160 EXPECT_EQ(1970, time_exploded.year); |
| 161 EXPECT_EQ(1, time_exploded.month); | 161 EXPECT_EQ(1, time_exploded.month); |
| 162 EXPECT_EQ(1, time_exploded.day_of_month); | 162 EXPECT_EQ(1, time_exploded.day_of_month); |
| 163 EXPECT_EQ(0, time_exploded.hour); | 163 EXPECT_EQ(0, time_exploded.hour); |
| 164 EXPECT_EQ(0, time_exploded.minute); | 164 EXPECT_EQ(0, time_exploded.minute); |
| 165 EXPECT_EQ(0, time_exploded.second); | 165 EXPECT_EQ(0, time_exploded.second); |
| 166 } | 166 } |
| 167 | 167 |
| 168 // Test date with a real date input. | 168 // Test date with a real date input. |
| 169 { | 169 { |
| 170 ExecuteNotificationObserver observer; | 170 ExecuteNotificationObserver observer; |
| 171 ExecuteJavascriptAndGetValue("new Date(Date.UTC(2006, 7, 16, 12, 0, 15));", | 171 ExecuteJavascriptAndGetValue("new Date(Date.UTC(2006, 7, 16, 12, 0, 15));", |
| 172 &observer); | 172 &observer); |
| 173 EXPECT_EQ(Value::TYPE_REAL, observer.value()->GetType()); | 173 EXPECT_EQ(Value::TYPE_DOUBLE, observer.value()->GetType()); |
| 174 double date_seconds; | 174 double date_seconds; |
| 175 EXPECT_TRUE(observer.value()->GetAsReal(&date_seconds)); | 175 EXPECT_TRUE(observer.value()->GetAsDouble(&date_seconds)); |
| 176 | 176 |
| 177 base::Time time = base::Time::FromDoubleT(date_seconds); | 177 base::Time time = base::Time::FromDoubleT(date_seconds); |
| 178 | 178 |
| 179 base::Time::Exploded time_exploded; | 179 base::Time::Exploded time_exploded; |
| 180 time.UTCExplode(&time_exploded); | 180 time.UTCExplode(&time_exploded); |
| 181 EXPECT_EQ(2006, time_exploded.year); | 181 EXPECT_EQ(2006, time_exploded.year); |
| 182 // Subtle; 0 based in JS, 1 based in base::Time: | 182 // Subtle; 0 based in JS, 1 based in base::Time: |
| 183 EXPECT_EQ(8, time_exploded.month); | 183 EXPECT_EQ(8, time_exploded.month); |
| 184 EXPECT_EQ(16, time_exploded.day_of_month); | 184 EXPECT_EQ(16, time_exploded.day_of_month); |
| 185 EXPECT_EQ(12, time_exploded.hour); | 185 EXPECT_EQ(12, time_exploded.hour); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 216 | 216 |
| 217 ui_test_utils::NavigateToURL(browser(), test_url); | 217 ui_test_utils::NavigateToURL(browser(), test_url); |
| 218 | 218 |
| 219 TabContents* tab_contents = browser()->GetSelectedTabContents(); | 219 TabContents* tab_contents = browser()->GetSelectedTabContents(); |
| 220 ASSERT_EQ(UTF8ToUTF16(test_url.spec() + " failed to load"), | 220 ASSERT_EQ(UTF8ToUTF16(test_url.spec() + " failed to load"), |
| 221 tab_contents->GetTitle()); | 221 tab_contents->GetTitle()); |
| 222 | 222 |
| 223 EXPECT_TRUE(tab_contents->GetTabSpecificContentSettings()->IsContentBlocked( | 223 EXPECT_TRUE(tab_contents->GetTabSpecificContentSettings()->IsContentBlocked( |
| 224 CONTENT_SETTINGS_TYPE_COOKIES)); | 224 CONTENT_SETTINGS_TYPE_COOKIES)); |
| 225 } | 225 } |
| OLD | NEW |