summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-28 10:41:44 +0000
committerhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-28 10:41:44 +0000
commit59d21b3166b3999c9f5006e97ac74d92516a093d (patch)
treeddf42fdd966b563d30e84b8ae5300dcfdc8e8513
parent31ad828b11da49ba704a42da5834ea28848fa480 (diff)
downloadchromium_src-59d21b3166b3999c9f5006e97ac74d92516a093d.zip
chromium_src-59d21b3166b3999c9f5006e97ac74d92516a093d.tar.gz
chromium_src-59d21b3166b3999c9f5006e97ac74d92516a093d.tar.bz2
drive: Add TestChangeListLoaderObserver
To verify ChangeListLoader calls observers' methods correctly BUG=161703 TEST=unit_tests --gtest_filter="ChangeListLoaderTest.*" R=kinaba@chromium.org Review URL: https://codereview.chromium.org/18172006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@209133 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/drive/change_list_loader_unittest.cc50
1 files changed, 50 insertions, 0 deletions
diff --git a/chrome/browser/chromeos/drive/change_list_loader_unittest.cc b/chrome/browser/chromeos/drive/change_list_loader_unittest.cc
index 4a25350..608eb8d 100644
--- a/chrome/browser/chromeos/drive/change_list_loader_unittest.cc
+++ b/chrome/browser/chromeos/drive/change_list_loader_unittest.cc
@@ -7,6 +7,7 @@
#include "base/files/scoped_temp_dir.h"
#include "base/memory/scoped_ptr.h"
#include "base/run_loop.h"
+#include "chrome/browser/chromeos/drive/change_list_loader_observer.h"
#include "chrome/browser/chromeos/drive/file_cache.h"
#include "chrome/browser/chromeos/drive/job_scheduler.h"
#include "chrome/browser/chromeos/drive/resource_metadata.h"
@@ -20,6 +21,50 @@
namespace drive {
namespace internal {
+class TestChangeListLoaderObserver : public ChangeListLoaderObserver {
+ public:
+ explicit TestChangeListLoaderObserver(ChangeListLoader* loader)
+ : loader_(loader),
+ load_from_server_complete_count_(0),
+ initial_load_complete_count_(0) {
+ loader_->AddObserver(this);
+ }
+
+ virtual ~TestChangeListLoaderObserver() {
+ loader_->RemoveObserver(this);
+ }
+
+ const std::set<base::FilePath>& changed_directories() const {
+ return changed_directories_;
+ }
+ int load_from_server_complete_count() const {
+ return load_from_server_complete_count_;
+ }
+ int initial_load_complete_count() const {
+ return initial_load_complete_count_;
+ }
+
+ // ChageListObserver overrides:
+ virtual void OnDirectoryChanged(
+ const base::FilePath& directory_path) OVERRIDE {
+ changed_directories_.insert(directory_path);
+ }
+ virtual void OnLoadFromServerComplete() OVERRIDE {
+ ++load_from_server_complete_count_;
+ }
+ virtual void OnInitialLoadComplete() OVERRIDE {
+ ++initial_load_complete_count_;
+ }
+
+ private:
+ ChangeListLoader* loader_;
+ std::set<base::FilePath> changed_directories_;
+ int load_from_server_complete_count_;
+ int initial_load_complete_count_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestChangeListLoaderObserver);
+};
+
class ChangeListLoaderTest : public testing::Test {
protected:
virtual void SetUp() OVERRIDE {
@@ -68,6 +113,8 @@ TEST_F(ChangeListLoaderTest, LoadIfNeeded) {
EXPECT_FALSE(change_list_loader_->IsRefreshing());
// Start initial load.
+ TestChangeListLoaderObserver observer(change_list_loader_.get());
+
FileError error = FILE_ERROR_FAILED;
change_list_loader_->LoadIfNeeded(
DirectoryFetchInfo(),
@@ -79,6 +126,9 @@ TEST_F(ChangeListLoaderTest, LoadIfNeeded) {
EXPECT_FALSE(change_list_loader_->IsRefreshing());
EXPECT_LT(0, metadata_->GetLargestChangestamp());
EXPECT_EQ(1, drive_service_->resource_list_load_count());
+ EXPECT_EQ(1, observer.initial_load_complete_count());
+ EXPECT_EQ(1, observer.load_from_server_complete_count());
+ EXPECT_TRUE(observer.changed_directories().empty());
// Reload. This should result in no-op.
int64 previous_changestamp = metadata_->GetLargestChangestamp();