| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ios/chrome/browser/web_resource/web_resource_util.h" | 5 #include "ios/chrome/browser/web_resource/web_resource_util.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 scoped_task_environment_.RunUntilIdle(); | 54 scoped_task_environment_.RunUntilIdle(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 base::test::ScopedTaskEnvironment scoped_task_environment_; | 57 base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 58 std::string error_; | 58 std::string error_; |
| 59 std::unique_ptr<base::Value> value_; | 59 std::unique_ptr<base::Value> value_; |
| 60 bool error_called_; | 60 bool error_called_; |
| 61 bool success_called_; | 61 bool success_called_; |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 // TODO(crbug.com/728216): Disabled because | 64 TEST_F(WebResourceUtilTest, Success) { |
| 65 // ScopedTaskEnvironment::RunUntilIdle() may hang. | |
| 66 TEST_F(WebResourceUtilTest, DISABLED_Success) { | |
| 67 const std::string kExpectedKey("foo"); | 65 const std::string kExpectedKey("foo"); |
| 68 const std::string kExpectedValue("bar"); | 66 const std::string kExpectedValue("bar"); |
| 69 std::string json = base::StringPrintf("{\"%s\":\"%s\"}", kExpectedKey.c_str(), | 67 std::string json = base::StringPrintf("{\"%s\":\"%s\"}", kExpectedKey.c_str(), |
| 70 kExpectedValue.c_str()); | 68 kExpectedValue.c_str()); |
| 71 GetIOSChromeParseJSONCallback().Run(json, GetSuccessCallback(), | 69 GetIOSChromeParseJSONCallback().Run(json, GetSuccessCallback(), |
| 72 GetErrorCallback()); | 70 GetErrorCallback()); |
| 73 | 71 |
| 74 FlushBackgroundTasks(); | 72 FlushBackgroundTasks(); |
| 75 | 73 |
| 76 // The success callback is called with the reference value. | 74 // The success callback is called with the reference value. |
| 77 EXPECT_FALSE(error_called_); | 75 EXPECT_FALSE(error_called_); |
| 78 EXPECT_TRUE(success_called_); | 76 EXPECT_TRUE(success_called_); |
| 79 | 77 |
| 80 base::DictionaryValue* dictionary = nullptr; | 78 base::DictionaryValue* dictionary = nullptr; |
| 81 ASSERT_TRUE(value_->GetAsDictionary(&dictionary)); | 79 ASSERT_TRUE(value_->GetAsDictionary(&dictionary)); |
| 82 EXPECT_EQ(1u, dictionary->size()); | 80 EXPECT_EQ(1u, dictionary->size()); |
| 83 base::Value* actual_value = nullptr; | 81 base::Value* actual_value = nullptr; |
| 84 ASSERT_TRUE(dictionary->Get(kExpectedKey, &actual_value)); | 82 ASSERT_TRUE(dictionary->Get(kExpectedKey, &actual_value)); |
| 85 std::string actual_value_as_string; | 83 std::string actual_value_as_string; |
| 86 EXPECT_TRUE(actual_value->GetAsString(&actual_value_as_string)); | 84 EXPECT_TRUE(actual_value->GetAsString(&actual_value_as_string)); |
| 87 EXPECT_EQ(kExpectedValue, actual_value_as_string); | 85 EXPECT_EQ(kExpectedValue, actual_value_as_string); |
| 88 } | 86 } |
| 89 | 87 |
| 90 // Only DictionaryValues are expected. | 88 // Only DictionartValues are expected. |
| 91 // TODO(crbug.com/728216): Disabled because | 89 TEST_F(WebResourceUtilTest, UnexpectedValue) { |
| 92 // ScopedTaskEnvironment::RunUntilIdle() may hang. | |
| 93 TEST_F(WebResourceUtilTest, DISABLED_UnexpectedValue) { | |
| 94 GetIOSChromeParseJSONCallback().Run("foo", GetSuccessCallback(), | 90 GetIOSChromeParseJSONCallback().Run("foo", GetSuccessCallback(), |
| 95 GetErrorCallback()); | 91 GetErrorCallback()); |
| 96 | 92 |
| 97 FlushBackgroundTasks(); | 93 FlushBackgroundTasks(); |
| 98 | 94 |
| 99 // The error callback is called. | 95 // The error callback is called. |
| 100 EXPECT_TRUE(error_called_); | 96 EXPECT_TRUE(error_called_); |
| 101 EXPECT_FALSE(success_called_); | 97 EXPECT_FALSE(success_called_); |
| 102 EXPECT_FALSE(error_.empty()); | 98 EXPECT_FALSE(error_.empty()); |
| 103 } | 99 } |
| 104 | 100 |
| 105 // Empty data is not expected. | 101 // Empty data is not expected. |
| 106 // TODO(crbug.com/728216): Disabled because | 102 TEST_F(WebResourceUtilTest, EmptyValue) { |
| 107 // ScopedTaskEnvironment::RunUntilIdle() may hang. | |
| 108 TEST_F(WebResourceUtilTest, DISABLED_EmptyValue) { | |
| 109 GetIOSChromeParseJSONCallback().Run(std::string(), GetSuccessCallback(), | 103 GetIOSChromeParseJSONCallback().Run(std::string(), GetSuccessCallback(), |
| 110 GetErrorCallback()); | 104 GetErrorCallback()); |
| 111 | 105 |
| 112 FlushBackgroundTasks(); | 106 FlushBackgroundTasks(); |
| 113 | 107 |
| 114 // The error callback is called. | 108 // The error callback is called. |
| 115 EXPECT_TRUE(error_called_); | 109 EXPECT_TRUE(error_called_); |
| 116 EXPECT_FALSE(success_called_); | 110 EXPECT_FALSE(success_called_); |
| 117 EXPECT_FALSE(error_.empty()); | 111 EXPECT_FALSE(error_.empty()); |
| 118 } | 112 } |
| 119 | 113 |
| 120 // Wrong syntax. | 114 // Wrong syntax. |
| 121 // TODO(crbug.com/728216): Disabled because | 115 TEST_F(WebResourceUtilTest, SyntaxError) { |
| 122 // ScopedTaskEnvironment::RunUntilIdle() may hang. | |
| 123 TEST_F(WebResourceUtilTest, DISABLED_SyntaxError) { | |
| 124 GetIOSChromeParseJSONCallback().Run("%$[", GetSuccessCallback(), | 116 GetIOSChromeParseJSONCallback().Run("%$[", GetSuccessCallback(), |
| 125 GetErrorCallback()); | 117 GetErrorCallback()); |
| 126 | 118 |
| 127 FlushBackgroundTasks(); | 119 FlushBackgroundTasks(); |
| 128 | 120 |
| 129 // The error callback is called. | 121 // The error callback is called. |
| 130 EXPECT_TRUE(error_called_); | 122 EXPECT_TRUE(error_called_); |
| 131 EXPECT_FALSE(success_called_); | 123 EXPECT_FALSE(success_called_); |
| 132 EXPECT_FALSE(error_.empty()); | 124 EXPECT_FALSE(error_.empty()); |
| 133 } | 125 } |
| 134 | 126 |
| 135 } // namespace web_resource | 127 } // namespace web_resource |
| OLD | NEW |