Chromium Code Reviews| 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 "chrome/browser/google_apis/base_requests.h" | 5 #include "chrome/browser/google_apis/base_requests.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 } // namespace | 40 } // namespace |
| 41 | 41 |
| 42 class BaseRequestsTest : public testing::Test { | 42 class BaseRequestsTest : public testing::Test { |
| 43 public: | 43 public: |
| 44 virtual void SetUp() OVERRIDE { | 44 virtual void SetUp() OVERRIDE { |
| 45 profile_.reset(new TestingProfile); | 45 profile_.reset(new TestingProfile); |
| 46 sender_.reset(new RequestSender(profile_.get(), | 46 sender_.reset(new RequestSender(profile_.get(), |
| 47 NULL /* url_request_context_getter */, | 47 NULL /* url_request_context_getter */, |
| 48 message_loop_.message_loop_proxy(), | |
| 48 std::vector<std::string>() /* scopes */, | 49 std::vector<std::string>() /* scopes */, |
| 49 std::string() /* custom user agent */)); | 50 std::string() /* custom user agent */)); |
| 50 sender_->Initialize(); | 51 sender_->Initialize(); |
| 51 } | 52 } |
| 52 | 53 |
| 53 base::MessageLoop message_loop_; | 54 base::MessageLoop message_loop_; |
| 54 scoped_ptr<TestingProfile> profile_; | 55 scoped_ptr<TestingProfile> profile_; |
| 55 scoped_ptr<RequestSender> sender_; | 56 scoped_ptr<RequestSender> sender_; |
| 56 }; | 57 }; |
| 57 | 58 |
| 58 TEST_F(BaseRequestsTest, ParseValidJson) { | 59 TEST_F(BaseRequestsTest, ParseValidJson) { |
| 59 scoped_ptr<base::Value> json; | 60 scoped_ptr<base::Value> json; |
| 60 ParseJson(kValidJsonString, | 61 ParseJson(message_loop_.message_loop_proxy(), |
| 62 kValidJsonString, | |
| 61 base::Bind(test_util::CreateCopyResultCallback(&json))); | 63 base::Bind(test_util::CreateCopyResultCallback(&json))); |
| 62 // Should wait for a blocking pool task, as the JSON parsing is done in the | 64 // Should wait for a blocking pool task, as the JSON parsing is done in the |
| 63 // blocking pool. | 65 // blocking pool. |
| 64 test_util::RunBlockingPoolTask(); | 66 test_util::RunBlockingPoolTask(); |
|
satorux1
2013/07/08 03:54:22
this looks unnecessary?
| |
| 65 | 67 |
| 66 DictionaryValue* root_dict = NULL; | 68 DictionaryValue* root_dict = NULL; |
| 67 ASSERT_TRUE(json); | 69 ASSERT_TRUE(json); |
| 68 ASSERT_TRUE(json->GetAsDictionary(&root_dict)); | 70 ASSERT_TRUE(json->GetAsDictionary(&root_dict)); |
| 69 | 71 |
| 70 int int_value = 0; | 72 int int_value = 0; |
| 71 ASSERT_TRUE(root_dict->GetInteger("test", &int_value)); | 73 ASSERT_TRUE(root_dict->GetInteger("test", &int_value)); |
| 72 EXPECT_EQ(123, int_value); | 74 EXPECT_EQ(123, int_value); |
| 73 } | 75 } |
| 74 | 76 |
| 75 TEST_F(BaseRequestsTest, ParseInvalidJson) { | 77 TEST_F(BaseRequestsTest, ParseInvalidJson) { |
| 76 // Initialize with a valid pointer to verify that null is indeed assigned. | 78 // Initialize with a valid pointer to verify that null is indeed assigned. |
| 77 scoped_ptr<base::Value> json(base::Value::CreateNullValue()); | 79 scoped_ptr<base::Value> json(base::Value::CreateNullValue()); |
| 78 ParseJson(kInvalidJsonString, | 80 ParseJson(message_loop_.message_loop_proxy(), |
| 81 kInvalidJsonString, | |
| 79 base::Bind(test_util::CreateCopyResultCallback(&json))); | 82 base::Bind(test_util::CreateCopyResultCallback(&json))); |
| 80 // Should wait for a blocking pool task, as the JSON parsing is done in the | 83 // Should wait for a blocking pool task, as the JSON parsing is done in the |
| 81 // blocking pool. | 84 // blocking pool. |
| 82 test_util::RunBlockingPoolTask(); | 85 test_util::RunBlockingPoolTask(); |
| 83 | 86 |
| 84 EXPECT_FALSE(json); | 87 EXPECT_FALSE(json); |
| 85 } | 88 } |
| 86 | 89 |
| 87 TEST_F(BaseRequestsTest, GetDataRequestParseValidResponse) { | 90 TEST_F(BaseRequestsTest, GetDataRequestParseValidResponse) { |
| 88 GDataErrorCode error = GDATA_OTHER_ERROR; | 91 GDataErrorCode error = GDATA_OTHER_ERROR; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 112 get_data_request->ParseResponse(HTTP_SUCCESS, kInvalidJsonString); | 115 get_data_request->ParseResponse(HTTP_SUCCESS, kInvalidJsonString); |
| 113 // Should wait for a blocking pool task, as the JSON parsing is done in the | 116 // Should wait for a blocking pool task, as the JSON parsing is done in the |
| 114 // blocking pool. | 117 // blocking pool. |
| 115 test_util::RunBlockingPoolTask(); | 118 test_util::RunBlockingPoolTask(); |
| 116 | 119 |
| 117 EXPECT_EQ(GDATA_PARSE_ERROR, error); | 120 EXPECT_EQ(GDATA_PARSE_ERROR, error); |
| 118 EXPECT_FALSE(value); | 121 EXPECT_FALSE(value); |
| 119 } | 122 } |
| 120 | 123 |
| 121 } // namespace google_apis | 124 } // namespace google_apis |
| OLD | NEW |