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 | 9 |
9 #include "base/bind.h" | 10 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
12 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
13 #include "base/values.h" | 14 #include "base/values.h" |
14 #include "ios/web/public/web_thread.h" | 15 #include "ios/web/public/web_thread.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 | 17 |
17 namespace web_resource { | 18 namespace web_resource { |
18 | 19 |
19 class WebResourceUtilTest : public testing::Test { | 20 class WebResourceUtilTest : public testing::Test { |
20 protected: | 21 protected: |
21 WebResourceUtilTest() : error_called_(false), success_called_(false) {} | 22 WebResourceUtilTest() : error_called_(false), success_called_(false) {} |
22 ~WebResourceUtilTest() override {} | 23 ~WebResourceUtilTest() override {} |
23 | 24 |
24 WebResourceService::SuccessCallback GetSuccessCallback() { | 25 WebResourceService::SuccessCallback GetSuccessCallback() { |
25 return base::Bind(&WebResourceUtilTest::OnParseSuccess, | 26 return base::Bind(&WebResourceUtilTest::OnParseSuccess, |
26 base::Unretained(this)); | 27 base::Unretained(this)); |
27 } | 28 } |
28 | 29 |
29 WebResourceService::ErrorCallback GetErrorCallback() { | 30 WebResourceService::ErrorCallback GetErrorCallback() { |
30 return base::Bind(&WebResourceUtilTest::OnParseError, | 31 return base::Bind(&WebResourceUtilTest::OnParseError, |
31 base::Unretained(this)); | 32 base::Unretained(this)); |
32 } | 33 } |
33 | 34 |
34 // Called on success. | 35 // Called on success. |
35 void OnParseSuccess(scoped_ptr<base::Value> value) { | 36 void OnParseSuccess(scoped_ptr<base::Value> value) { |
36 success_called_ = true; | 37 success_called_ = true; |
37 value_ = value.Pass(); | 38 value_ = std::move(value); |
38 } | 39 } |
39 | 40 |
40 // Called on error. | 41 // Called on error. |
41 void OnParseError(const std::string& error) { | 42 void OnParseError(const std::string& error) { |
42 error_called_ = true; | 43 error_called_ = true; |
43 error_ = error; | 44 error_ = error; |
44 } | 45 } |
45 | 46 |
46 void FlushBackgroundTasks() { | 47 void FlushBackgroundTasks() { |
47 // The function is not synchronous, callbacks are not called before flushing | 48 // The function is not synchronous, callbacks are not called before flushing |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 118 |
118 FlushBackgroundTasks(); | 119 FlushBackgroundTasks(); |
119 | 120 |
120 // The error callback is called. | 121 // The error callback is called. |
121 EXPECT_TRUE(error_called_); | 122 EXPECT_TRUE(error_called_); |
122 EXPECT_FALSE(success_called_); | 123 EXPECT_FALSE(success_called_); |
123 EXPECT_FALSE(error_.empty()); | 124 EXPECT_FALSE(error_.empty()); |
124 } | 125 } |
125 | 126 |
126 } // namespace web_resource | 127 } // namespace web_resource |
OLD | NEW |