Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / drive / drive_app_registry_unittest.cc
index 630720b..64ee58c 100644 (file)
@@ -5,7 +5,10 @@
 #include "chrome/browser/drive/drive_app_registry.h"
 
 #include "base/files/file_path.h"
+#include "base/macros.h"
 #include "base/run_loop.h"
+#include "base/values.h"
+#include "chrome/browser/drive/drive_app_registry_observer.h"
 #include "chrome/browser/drive/fake_drive_service.h"
 #include "content/public/test/test_browser_thread_bundle.h"
 #include "google_apis/drive/drive_api_parser.h"
 
 namespace drive {
 
+class TestDriveAppRegistryObserver : public DriveAppRegistryObserver {
+ public:
+  explicit TestDriveAppRegistryObserver(DriveAppRegistry* registry)
+      : registry_(registry),
+        update_count_(0) {
+    registry_->AddObserver(this);
+  }
+  virtual ~TestDriveAppRegistryObserver() {
+    registry_->RemoveObserver(this);
+  }
+
+  int update_count() const { return update_count_; }
+
+ private:
+  // DriveAppRegistryObserver overrides:
+  virtual void OnDriveAppRegistryUpdated() OVERRIDE { ++update_count_; }
+
+  DriveAppRegistry* registry_;
+  int update_count_;
+  DISALLOW_COPY_AND_ASSIGN(TestDriveAppRegistryObserver);
+};
+
 class DriveAppRegistryTest : public testing::Test {
  protected:
   virtual void SetUp() OVERRIDE {
@@ -46,8 +71,11 @@ class DriveAppRegistryTest : public testing::Test {
 };
 
 TEST_F(DriveAppRegistryTest, BasicParse) {
+  TestDriveAppRegistryObserver observer(apps_registry_.get());
+
   apps_registry_->Update();
   base::RunLoop().RunUntilIdle();
+  EXPECT_EQ(1, observer.update_count());
 
   std::vector<DriveAppInfo> apps;
   apps_registry_->GetAppList(&apps);
@@ -62,8 +90,11 @@ TEST_F(DriveAppRegistryTest, BasicParse) {
 }
 
 TEST_F(DriveAppRegistryTest, LoadAndFindDriveApps) {
+  TestDriveAppRegistryObserver observer(apps_registry_.get());
+
   apps_registry_->Update();
   base::RunLoop().RunUntilIdle();
+  EXPECT_EQ(1, observer.update_count());
 
   // Find by primary extension 'exe'.
   std::vector<DriveAppInfo> ext_results;
@@ -93,7 +124,9 @@ TEST_F(DriveAppRegistryTest, UpdateFromAppList) {
   scoped_ptr<google_apis::AppList> app_list(
       google_apis::AppList::CreateFrom(*app_info_value));
 
+  TestDriveAppRegistryObserver observer(apps_registry_.get());
   apps_registry_->UpdateFromAppList(*app_list);
+  EXPECT_EQ(1, observer.update_count());
 
   // Confirm that something was loaded from applist.json.
   std::vector<DriveAppInfo> ext_results;
@@ -103,20 +136,25 @@ TEST_F(DriveAppRegistryTest, UpdateFromAppList) {
 }
 
 TEST_F(DriveAppRegistryTest, MultipleUpdate) {
+  TestDriveAppRegistryObserver observer(apps_registry_.get());
+
   // Call Update().
   apps_registry_->Update();
+  EXPECT_EQ(0, observer.update_count());
 
   // Call Update() again.
   // This call should be ignored because there is already an ongoing update.
   apps_registry_->Update();
+  EXPECT_EQ(0, observer.update_count());
 
   // The app list should be loaded only once.
   base::RunLoop().RunUntilIdle();
   EXPECT_EQ(1, fake_drive_service_->app_list_load_count());
+  EXPECT_EQ(1, observer.update_count());
 }
 
 TEST(DriveAppRegistryUtilTest, FindPreferredIcon_Empty) {
-  google_apis::InstalledApp::IconList icons;
+  DriveAppInfo::IconList icons;
   EXPECT_EQ("",
             util::FindPreferredIcon(icons, util::kPreferredIconSize).spec());
 }
@@ -127,7 +165,7 @@ TEST(DriveAppRegistryUtilTest, FindPreferredIcon_) {
   const char kBiggerIconUrl[] = "http://example.com/bigger.png";
   const int kMediumSize = 16;
 
-  google_apis::InstalledApp::IconList icons;
+  DriveAppInfo::IconList icons;
   // The icons are not sorted by the size.
   icons.push_back(std::make_pair(kMediumSize,
                                  GURL(kMediumIconUrl)));