| 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 <stdint.h> |
| 6 |
| 7 #include <limits> |
| 5 #include <string> | 8 #include <string> |
| 6 | 9 |
| 7 #include "base/bind.h" | 10 #include "base/bind.h" |
| 8 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 9 #include "base/logging.h" | 12 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 12 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
| 13 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 14 #include "base/values.h" | 17 #include "base/values.h" |
| 15 #include "chrome/browser/download/download_query.h" | 18 #include "chrome/browser/download/download_query.h" |
| 16 #include "content/public/test/mock_download_item.h" | 19 #include "content/public/test/mock_download_item.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 22 |
| 20 using ::testing::Return; | 23 using ::testing::Return; |
| 21 using ::testing::ReturnRef; | 24 using ::testing::ReturnRef; |
| 22 using ::testing::_; | 25 using ::testing::_; |
| 23 using base::Time; | 26 using base::Time; |
| 24 using base::Value; | 27 using base::Value; |
| 25 using content::DownloadItem; | 28 using content::DownloadItem; |
| 26 typedef DownloadQuery::DownloadVector DownloadVector; | 29 typedef DownloadQuery::DownloadVector DownloadVector; |
| 27 | 30 |
| 28 namespace { | 31 namespace { |
| 29 | 32 |
| 30 static const int kSomeKnownTime = 1355864160; | 33 static const int kSomeKnownTime = 1355864160; |
| 31 static const char kSomeKnownTime8601[] = "2012-12-18T20:56:0"; | 34 static const char kSomeKnownTime8601[] = "2012-12-18T20:56:0"; |
| 32 static const char k8601Suffix[] = ".000Z"; | 35 static const char k8601Suffix[] = ".000Z"; |
| 33 | 36 |
| 34 bool IdNotEqual(uint32 not_id, const DownloadItem& item) { | 37 bool IdNotEqual(uint32_t not_id, const DownloadItem& item) { |
| 35 return item.GetId() != not_id; | 38 return item.GetId() != not_id; |
| 36 } | 39 } |
| 37 | 40 |
| 38 bool AlwaysReturn(bool result, const DownloadItem& item) { | 41 bool AlwaysReturn(bool result, const DownloadItem& item) { |
| 39 return result; | 42 return result; |
| 40 } | 43 } |
| 41 | 44 |
| 42 } // anonymous namespace | 45 } // anonymous namespace |
| 43 | 46 |
| 44 class DownloadQueryTest : public testing::Test { | 47 class DownloadQueryTest : public testing::Test { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 } | 153 } |
| 151 #endif | 154 #endif |
| 152 | 155 |
| 153 TEST_F(DownloadQueryTest, DownloadQueryTest_ZeroItems) { | 156 TEST_F(DownloadQueryTest, DownloadQueryTest_ZeroItems) { |
| 154 Search(); | 157 Search(); |
| 155 EXPECT_EQ(0U, results()->size()); | 158 EXPECT_EQ(0U, results()->size()); |
| 156 } | 159 } |
| 157 | 160 |
| 158 TEST_F(DownloadQueryTest, DownloadQueryTest_InvalidFilter) { | 161 TEST_F(DownloadQueryTest, DownloadQueryTest_InvalidFilter) { |
| 159 scoped_ptr<base::Value> value(new base::FundamentalValue(0)); | 162 scoped_ptr<base::Value> value(new base::FundamentalValue(0)); |
| 160 EXPECT_FALSE(query()->AddFilter( | 163 EXPECT_FALSE(query()->AddFilter(static_cast<DownloadQuery::FilterType>( |
| 161 static_cast<DownloadQuery::FilterType>(kint32max), | 164 std::numeric_limits<int32_t>::max()), |
| 162 *value.get())); | 165 *value.get())); |
| 163 } | 166 } |
| 164 | 167 |
| 165 TEST_F(DownloadQueryTest, DownloadQueryTest_EmptyQuery) { | 168 TEST_F(DownloadQueryTest, DownloadQueryTest_EmptyQuery) { |
| 166 CreateMocks(2); | 169 CreateMocks(2); |
| 167 Search(); | 170 Search(); |
| 168 ASSERT_EQ(2U, results()->size()); | 171 ASSERT_EQ(2U, results()->size()); |
| 169 ASSERT_EQ(0U, results()->at(0)->GetId()); | 172 ASSERT_EQ(0U, results()->at(0)->GetId()); |
| 170 ASSERT_EQ(1U, results()->at(1)->GetId()); | 173 ASSERT_EQ(1U, results()->at(1)->GetId()); |
| 171 } | 174 } |
| 172 | 175 |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 base::Time start = base::Time::Now(); | 635 base::Time start = base::Time::Now(); |
| 633 Search(); | 636 Search(); |
| 634 base::Time end = base::Time::Now(); | 637 base::Time end = base::Time::Now(); |
| 635 double nanos = (end - start).InMillisecondsF() * 1000.0 * 1000.0; | 638 double nanos = (end - start).InMillisecondsF() * 1000.0 * 1000.0; |
| 636 double nanos_per_item = nanos / static_cast<double>(kNumItems); | 639 double nanos_per_item = nanos / static_cast<double>(kNumItems); |
| 637 double nanos_per_item_per_filter = nanos_per_item | 640 double nanos_per_item_per_filter = nanos_per_item |
| 638 / static_cast<double>(kNumFilters); | 641 / static_cast<double>(kNumFilters); |
| 639 std::cout << "Search took " << nanos_per_item_per_filter | 642 std::cout << "Search took " << nanos_per_item_per_filter |
| 640 << " nanoseconds per item per filter.\n"; | 643 << " nanoseconds per item per filter.\n"; |
| 641 } | 644 } |
| OLD | NEW |