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/fake_drive_service.h" | 5 #include "chrome/browser/google_apis/fake_drive_service.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 &resource_list)); | 78 &resource_list)); |
79 message_loop_.RunUntilIdle(); | 79 message_loop_.RunUntilIdle(); |
80 | 80 |
81 EXPECT_EQ(HTTP_SUCCESS, error); | 81 EXPECT_EQ(HTTP_SUCCESS, error); |
82 ASSERT_TRUE(resource_list); | 82 ASSERT_TRUE(resource_list); |
83 // Do some sanity check. | 83 // Do some sanity check. |
84 EXPECT_EQ(12U, resource_list->entries().size()); | 84 EXPECT_EQ(12U, resource_list->entries().size()); |
85 EXPECT_EQ(1, fake_service_.resource_list_load_count()); | 85 EXPECT_EQ(1, fake_service_.resource_list_load_count()); |
86 } | 86 } |
87 | 87 |
| 88 TEST_F(FakeDriveServiceTest, GetResourceList_WithStartIndex) { |
| 89 ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json")); |
| 90 |
| 91 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 92 scoped_ptr<ResourceList> resource_list; |
| 93 fake_service_.GetResourceList( |
| 94 GURL("http://dummyurl/?start-index=2"), |
| 95 0, // start_changestamp |
| 96 "", // search_query |
| 97 false, // shared_with_me |
| 98 "", // directory_resource_id |
| 99 base::Bind(&test_util::CopyResultsFromGetResourceListCallback, |
| 100 &error, |
| 101 &resource_list)); |
| 102 message_loop_.RunUntilIdle(); |
| 103 |
| 104 EXPECT_EQ(HTTP_SUCCESS, error); |
| 105 ASSERT_TRUE(resource_list); |
| 106 // Because the start-index was set to 2, the size should be 10 instead of |
| 107 // 12 (the total number). |
| 108 EXPECT_EQ(10U, resource_list->entries().size()); |
| 109 EXPECT_EQ(1, fake_service_.resource_list_load_count()); |
| 110 } |
| 111 |
| 112 TEST_F(FakeDriveServiceTest, GetResourceList_WithStartIndexAndMaxResults) { |
| 113 ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json")); |
| 114 |
| 115 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 116 scoped_ptr<ResourceList> resource_list; |
| 117 fake_service_.GetResourceList( |
| 118 GURL("http://localhost/?start-index=2&max-results=5"), |
| 119 0, // start_changestamp |
| 120 "", // search_query |
| 121 false, // shared_with_me |
| 122 "", // directory_resource_id |
| 123 base::Bind(&test_util::CopyResultsFromGetResourceListCallback, |
| 124 &error, |
| 125 &resource_list)); |
| 126 message_loop_.RunUntilIdle(); |
| 127 |
| 128 EXPECT_EQ(HTTP_SUCCESS, error); |
| 129 ASSERT_TRUE(resource_list); |
| 130 // Because the max-results was set to 5, the size should be 5 instead of 10. |
| 131 EXPECT_EQ(5U, resource_list->entries().size()); |
| 132 EXPECT_EQ(1, fake_service_.resource_list_load_count()); |
| 133 // The next link should be provided. The new start-index should be |
| 134 // 2 (original start index) + 5 (max results). |
| 135 const google_apis::Link* next_link = |
| 136 resource_list->GetLinkByType(Link::LINK_NEXT); |
| 137 ASSERT_TRUE(next_link); |
| 138 EXPECT_EQ(GURL("http://localhost/?start-index=7&max-results=5"), |
| 139 next_link->href()); |
| 140 } |
| 141 |
| 142 TEST_F(FakeDriveServiceTest, GetResourceList_WithDefaultMaxResultsChanged) { |
| 143 ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json")); |
| 144 fake_service_.set_default_max_results(3); |
| 145 |
| 146 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 147 scoped_ptr<ResourceList> resource_list; |
| 148 fake_service_.GetResourceList( |
| 149 GURL(), |
| 150 0, // start_changestamp |
| 151 "", // search_query |
| 152 false, // shared_with_me |
| 153 "", // directory_resource_id |
| 154 base::Bind(&test_util::CopyResultsFromGetResourceListCallback, |
| 155 &error, |
| 156 &resource_list)); |
| 157 message_loop_.RunUntilIdle(); |
| 158 |
| 159 EXPECT_EQ(HTTP_SUCCESS, error); |
| 160 ASSERT_TRUE(resource_list); |
| 161 // Because the default max results was changed to 3, the size should be 3 |
| 162 // instead of 12 (the total number). |
| 163 EXPECT_EQ(3U, resource_list->entries().size()); |
| 164 EXPECT_EQ(1, fake_service_.resource_list_load_count()); |
| 165 // The next link should be provided. |
| 166 const google_apis::Link* next_link = |
| 167 resource_list->GetLinkByType(Link::LINK_NEXT); |
| 168 ASSERT_TRUE(next_link); |
| 169 EXPECT_EQ(GURL("http://localhost/?start-index=3&max-results=3"), |
| 170 next_link->href()); |
| 171 } |
| 172 |
88 TEST_F(FakeDriveServiceTest, GetResourceList_InRootDirectory) { | 173 TEST_F(FakeDriveServiceTest, GetResourceList_InRootDirectory) { |
89 ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json")); | 174 ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json")); |
90 | 175 |
91 GDataErrorCode error = GDATA_OTHER_ERROR; | 176 GDataErrorCode error = GDATA_OTHER_ERROR; |
92 scoped_ptr<ResourceList> resource_list; | 177 scoped_ptr<ResourceList> resource_list; |
93 fake_service_.GetResourceList( | 178 fake_service_.GetResourceList( |
94 GURL(), | 179 GURL(), |
95 0, // start_changestamp | 180 0, // start_changestamp |
96 "", // search_query | 181 "", // search_query |
97 false, // shared_with_me | 182 false, // shared_with_me |
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 base::Bind(&test_util::CopyResultsFromGetResourceEntryCallback, | 943 base::Bind(&test_util::CopyResultsFromGetResourceEntryCallback, |
859 &error, | 944 &error, |
860 &resource_entry)); | 945 &resource_entry)); |
861 message_loop_.RunUntilIdle(); | 946 message_loop_.RunUntilIdle(); |
862 | 947 |
863 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 948 EXPECT_EQ(GDATA_NO_CONNECTION, error); |
864 EXPECT_FALSE(resource_entry); | 949 EXPECT_FALSE(resource_entry); |
865 } | 950 } |
866 | 951 |
867 } // namespace google_apis | 952 } // namespace google_apis |
OLD | NEW |