| 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "chrome/browser/chromeos/gdata/gdata_operations.h" | 8 #include "chrome/browser/chromeos/gdata/gdata_operations.h" |
| 9 #include "chrome/browser/chromeos/gdata/gdata_operation_runner.h" | |
| 10 #include "chrome/browser/chromeos/gdata/gdata_test_util.h" | 9 #include "chrome/browser/chromeos/gdata/gdata_test_util.h" |
| 10 #include "chrome/browser/chromeos/gdata/operation_runner.h" |
| 11 #include "chrome/test/base/testing_profile.h" | 11 #include "chrome/test/base/testing_profile.h" |
| 12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "content/public/test/test_browser_thread.h" | 13 #include "content/public/test/test_browser_thread.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 namespace gdata { | 16 namespace gdata { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 class JsonParseTestGetDataOperation : public GetDataOperation { | 20 class JsonParseTestGetDataOperation : public GetDataOperation { |
| 21 public: | 21 public: |
| 22 JsonParseTestGetDataOperation(GDataOperationRegistry* registry, | 22 JsonParseTestGetDataOperation(OperationRegistry* registry, |
| 23 const GetDataCallback& callback) | 23 const GetDataCallback& callback) |
| 24 : GetDataOperation(registry, callback) { | 24 : GetDataOperation(registry, callback) { |
| 25 } | 25 } |
| 26 | 26 |
| 27 virtual ~JsonParseTestGetDataOperation() { | 27 virtual ~JsonParseTestGetDataOperation() { |
| 28 } | 28 } |
| 29 | 29 |
| 30 void NotifyStart() { | 30 void NotifyStart() { |
| 31 NotifyStartToOperationRegistry(); | 31 NotifyStartToOperationRegistry(); |
| 32 } | 32 } |
| 33 | 33 |
| 34 void NotifySuccess() { | 34 void NotifySuccess() { |
| 35 NotifySuccessToOperationRegistry(); | 35 NotifySuccessToOperationRegistry(); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void NotifyFailure() { | 38 void NotifyFailure() { |
| 39 NotifyFinish(GDataOperationRegistry::OPERATION_FAILED); | 39 NotifyFinish(OperationRegistry::OPERATION_FAILED); |
| 40 } | 40 } |
| 41 | 41 |
| 42 protected: | 42 protected: |
| 43 // GetDataOperation overrides: | 43 // GetDataOperation overrides: |
| 44 virtual GURL GetURL() const OVERRIDE { | 44 virtual GURL GetURL() const OVERRIDE { |
| 45 // This method is never called because this test does not fetch json from | 45 // This method is never called because this test does not fetch json from |
| 46 // network. | 46 // network. |
| 47 NOTREACHED(); | 47 NOTREACHED(); |
| 48 return GURL(); | 48 return GURL(); |
| 49 } | 49 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 60 } // namespace | 60 } // namespace |
| 61 | 61 |
| 62 class GDataOperationsTest : public testing::Test { | 62 class GDataOperationsTest : public testing::Test { |
| 63 protected: | 63 protected: |
| 64 GDataOperationsTest() | 64 GDataOperationsTest() |
| 65 : ui_thread_(content::BrowserThread::UI, &message_loop_) { | 65 : ui_thread_(content::BrowserThread::UI, &message_loop_) { |
| 66 } | 66 } |
| 67 | 67 |
| 68 virtual void SetUp() OVERRIDE { | 68 virtual void SetUp() OVERRIDE { |
| 69 profile_.reset(new TestingProfile); | 69 profile_.reset(new TestingProfile); |
| 70 runner_.reset(new GDataOperationRunner(profile_.get())); | 70 runner_.reset(new OperationRunner(profile_.get())); |
| 71 runner_->Initialize(); | 71 runner_->Initialize(); |
| 72 } | 72 } |
| 73 | 73 |
| 74 protected: | 74 protected: |
| 75 MessageLoopForUI message_loop_; | 75 MessageLoopForUI message_loop_; |
| 76 content::TestBrowserThread ui_thread_; | 76 content::TestBrowserThread ui_thread_; |
| 77 scoped_ptr<TestingProfile> profile_; | 77 scoped_ptr<TestingProfile> profile_; |
| 78 scoped_ptr<GDataOperationRunner> runner_; | 78 scoped_ptr<OperationRunner> runner_; |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 TEST_F(GDataOperationsTest, GetDataOperationParseJson) { | 81 TEST_F(GDataOperationsTest, GetDataOperationParseJson) { |
| 82 scoped_ptr<base::Value> value; | 82 scoped_ptr<base::Value> value; |
| 83 GDataErrorCode error; | 83 GDataErrorCode error; |
| 84 gdata::GetDataCallback cb = base::Bind(&GetDataOperationParseJsonCallback, | 84 gdata::GetDataCallback cb = base::Bind(&GetDataOperationParseJsonCallback, |
| 85 &error, | 85 &error, |
| 86 &value); | 86 &value); |
| 87 JsonParseTestGetDataOperation* getData = | 87 JsonParseTestGetDataOperation* getData = |
| 88 new JsonParseTestGetDataOperation(runner_->operation_registry(), cb); | 88 new JsonParseTestGetDataOperation(runner_->operation_registry(), cb); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 | 171 |
| 172 getData->ParseResponse(HTTP_SUCCESS, invalid_json_str); | 172 getData->ParseResponse(HTTP_SUCCESS, invalid_json_str); |
| 173 test_util::RunBlockingPoolTask(); | 173 test_util::RunBlockingPoolTask(); |
| 174 | 174 |
| 175 EXPECT_EQ(GDATA_PARSE_ERROR, error); | 175 EXPECT_EQ(GDATA_PARSE_ERROR, error); |
| 176 ASSERT_TRUE(value.get() == NULL); | 176 ASSERT_TRUE(value.get() == NULL); |
| 177 } | 177 } |
| 178 } | 178 } |
| 179 | 179 |
| 180 } // namespace gdata | 180 } // namespace gdata |
| OLD | NEW |