1 // Copyright (c) 2013 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "xwalk/sysapps/device_capabilities/storage_info_provider.h"
8 #include "base/message_loop/message_loop.h"
9 #include "content/public/test/test_browser_thread_bundle.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "xwalk/sysapps/common/sysapps_manager.h"
12 #include "xwalk/sysapps/device_capabilities/device_capabilities.h"
14 using xwalk::jsapi::device_capabilities::StorageUnit;
15 using xwalk::jsapi::device_capabilities::SystemStorage;
16 using xwalk::sysapps::StorageInfoProvider;
17 using xwalk::sysapps::SysAppsManager;
21 class TestObserver : public StorageInfoProvider::Observer {
26 void OnStorageAttached(const StorageUnit& storage) override {}
27 void OnStorageDetached(const StorageUnit& storage) override {}
31 StorageInfoProvider* provider(SysAppsManager::GetStorageInfoProvider());
32 EXPECT_TRUE(provider != NULL);
33 EXPECT_TRUE(provider->IsInitialized());
35 scoped_ptr<SystemStorage> info(provider->storage_info());
36 EXPECT_TRUE(info != NULL);
38 std::vector<linked_ptr<StorageUnit> > storages = info->storages;
40 // We should have at least one storage, otherwise where is the binary
41 // of this unit test being stored?
42 unsigned storage_count = storages.size();
43 EXPECT_GT(storage_count, 0u);
45 // The only information we can verify is the fact that the storage
46 // has some capacity and has an ID. The rest, like the name, can be empty.
47 for (size_t i = 0; i < storage_count; ++i) {
48 EXPECT_FALSE(storages[i]->id.empty());
49 EXPECT_GE(storages[i]->capacity, 0);
52 // We can just test if adding and removing the observers works, but
53 // without a fake backend, we cannot verify if the observers are getting
55 TestObserver test_observer;
56 provider->AddObserver(&test_observer);
57 provider->RemoveObserver(&test_observer);
59 base::MessageLoop::current()->Quit();
64 TEST(XWalkSysAppsDeviceCapabilitiesTest, StorageInfoProvider) {
65 // The StorageMonitor backend requires an UIThread up and running. Luckily
66 // the abstraction bellow does all the heavy lifting for us.
67 content::TestBrowserThreadBundle thread_bundle(
68 content::TestBrowserThreadBundle::IO_MAINLOOP);
70 StorageInfoProvider* provider(SysAppsManager::GetStorageInfoProvider());
71 EXPECT_TRUE(provider != NULL);
73 base::Closure closure = base::Bind(&TestClosure);
75 if (!provider->IsInitialized())
76 provider->AddOnInitCallback(closure);
78 base::MessageLoop::current()->PostTask(FROM_HERE, closure);
80 base::MessageLoop::current()->Run();