Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/macros.h" | 6 #include "base/macros.h" |
| 7 #include "base/memory/ref_counted_memory.h" | 7 #include "base/memory/ref_counted_memory.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "content/browser/webui/web_ui_data_source_impl.h" | 9 #include "content/browser/webui/web_ui_data_source_impl.h" |
| 10 #include "content/public/test/test_browser_thread_bundle.h" | 10 #include "content/public/test/test_browser_thread_bundle.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 std::string result(data->front_as<char>(), data->size()); | 96 std::string result(data->front_as<char>(), data->size()); |
| 97 EXPECT_NE(result.find("loadTimeData.data = {"), std::string::npos); | 97 EXPECT_NE(result.find("loadTimeData.data = {"), std::string::npos); |
| 98 EXPECT_NE(result.find("};"), std::string::npos); | 98 EXPECT_NE(result.find("};"), std::string::npos); |
| 99 } | 99 } |
| 100 | 100 |
| 101 TEST_F(WebUIDataSourceTest, EmptyStrings) { | 101 TEST_F(WebUIDataSourceTest, EmptyStrings) { |
| 102 source()->SetJsonPath("strings.js"); | 102 source()->SetJsonPath("strings.js"); |
| 103 StartDataRequest("strings.js", base::Bind(&EmptyStringsCallback)); | 103 StartDataRequest("strings.js", base::Bind(&EmptyStringsCallback)); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void SomeStringsCallback(scoped_refptr<base::RefCountedMemory> data) { | 106 void SomeValuesCallback(scoped_refptr<base::RefCountedMemory> data) { |
| 107 std::string result(data->front_as<char>(), data->size()); | 107 std::string result(data->front_as<char>(), data->size()); |
| 108 EXPECT_NE(result.find("\"flag\":true"), std::string::npos); | |
| 109 EXPECT_NE(result.find("\"counter\":10"), std::string::npos); | |
| 108 EXPECT_NE(result.find("\"planet\":\"pluto\""), std::string::npos); | 110 EXPECT_NE(result.find("\"planet\":\"pluto\""), std::string::npos); |
| 109 EXPECT_NE(result.find("\"button\":\"foo\""), std::string::npos); | 111 EXPECT_NE(result.find("\"button\":\"foo\""), std::string::npos); |
| 110 } | 112 } |
| 111 | 113 |
| 112 TEST_F(WebUIDataSourceTest, SomeStrings) { | 114 TEST_F(WebUIDataSourceTest, SomeValues) { |
| 113 source()->SetJsonPath("strings.js"); | 115 source()->SetJsonPath("strings.js"); |
| 116 source()->AddBoolean("flag", true); | |
| 117 source()->AddInteger("counter", 10); | |
|
tommycli
2016/10/06 18:29:56
maybe add a test for negative values also?
michaelpg
2016/10/06 18:58:34
Done.
| |
| 114 source()->AddString("planet", base::ASCIIToUTF16("pluto")); | 118 source()->AddString("planet", base::ASCIIToUTF16("pluto")); |
| 115 source()->AddLocalizedString("button", kDummyStringId); | 119 source()->AddLocalizedString("button", kDummyStringId); |
| 116 StartDataRequest("strings.js", base::Bind(&SomeStringsCallback)); | 120 StartDataRequest("strings.js", base::Bind(&SomeValuesCallback)); |
| 117 } | 121 } |
| 118 | 122 |
| 119 void DefaultResourceFoobarCallback(scoped_refptr<base::RefCountedMemory> data) { | 123 void DefaultResourceFoobarCallback(scoped_refptr<base::RefCountedMemory> data) { |
| 120 std::string result(data->front_as<char>(), data->size()); | 124 std::string result(data->front_as<char>(), data->size()); |
| 121 EXPECT_NE(result.find(kDummyDefaultResource), std::string::npos); | 125 EXPECT_NE(result.find(kDummyDefaultResource), std::string::npos); |
| 122 } | 126 } |
| 123 | 127 |
| 124 void DefaultResourceStringsCallback( | 128 void DefaultResourceStringsCallback( |
| 125 scoped_refptr<base::RefCountedMemory> data) { | 129 scoped_refptr<base::RefCountedMemory> data) { |
| 126 std::string result(data->front_as<char>(), data->size()); | 130 std::string result(data->front_as<char>(), data->size()); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 EXPECT_EQ(GetMimeType(".css.foo"), html); | 204 EXPECT_EQ(GetMimeType(".css.foo"), html); |
| 201 | 205 |
| 202 // With query strings. | 206 // With query strings. |
| 203 EXPECT_EQ(GetMimeType("foo?abc?abc"), html); | 207 EXPECT_EQ(GetMimeType("foo?abc?abc"), html); |
| 204 EXPECT_EQ(GetMimeType("foo.html?abc?abc"), html); | 208 EXPECT_EQ(GetMimeType("foo.html?abc?abc"), html); |
| 205 EXPECT_EQ(GetMimeType("foo.css?abc?abc"), css); | 209 EXPECT_EQ(GetMimeType("foo.css?abc?abc"), css); |
| 206 EXPECT_EQ(GetMimeType("foo.js?abc?abc"), js); | 210 EXPECT_EQ(GetMimeType("foo.js?abc?abc"), js); |
| 207 } | 211 } |
| 208 | 212 |
| 209 } // namespace content | 213 } // namespace content |
| OLD | NEW |