[safe-browsing] Database full hash matches like prefix match.
[chromium-blink-merge.git] / chrome / browser / apps / ephemeral_app_service_browsertest.cc
blobe59eec2e7f31342137b65aac2d0b030d50dc3184
1 // Copyright 2013 The Chromium Authors. 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 <vector>
7 #include "chrome/browser/apps/app_browsertest_util.h"
8 #include "chrome/browser/apps/ephemeral_app_service.h"
9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "content/public/test/test_utils.h"
12 #include "extensions/browser/extension_prefs.h"
13 #include "extensions/browser/extension_system.h"
14 #include "extensions/common/manifest.h"
16 using extensions::PlatformAppBrowserTest;
17 using extensions::Extension;
18 using extensions::ExtensionPrefs;
19 using extensions::ExtensionSystem;
21 namespace {
23 const int kNumTestApps = 2;
24 const char* kTestApps[] = {
25 "platform_apps/app_window/generic",
26 "platform_apps/minimal"
29 } // namespace
31 class EphemeralAppServiceBrowserTest : public PlatformAppBrowserTest {
32 protected:
33 void LoadApps() {
34 for (int i = 0; i < kNumTestApps; ++i) {
35 base::FilePath path = test_data_dir_.AppendASCII(kTestApps[i]);
36 const Extension* extension =
37 InstallExtensionWithSourceAndFlags(
38 path,
40 extensions::Manifest::INTERNAL,
41 Extension::IS_EPHEMERAL);
42 app_ids_.push_back(extension->id());
45 ASSERT_EQ(kNumTestApps, (int) app_ids_.size());
48 void GarbageCollectEphemeralApps() {
49 EphemeralAppService* ephemeral_service = EphemeralAppService::Get(
50 browser()->profile());
51 ASSERT_TRUE(ephemeral_service);
52 ephemeral_service->GarbageCollectApps();
55 std::vector<std::string> app_ids_;
58 // Verifies that inactive ephemeral apps are uninstalled and active apps are
59 // not removed. Extensive testing of the ephemeral app cache's replacement
60 // policies is done in the unit tests for EphemeralAppService. This is more
61 // like an integration test.
62 IN_PROC_BROWSER_TEST_F(EphemeralAppServiceBrowserTest,
63 GarbageCollectInactiveApps) {
64 LoadApps();
66 const base::Time time_now = base::Time::Now();
67 ExtensionPrefs* prefs = ExtensionPrefs::Get(browser()->profile());
68 ASSERT_TRUE(prefs);
70 // Set launch time for an inactive app.
71 std::string inactive_app_id = app_ids_[0];
72 base::Time inactive_launch = time_now -
73 base::TimeDelta::FromDays(EphemeralAppService::kAppInactiveThreshold + 1);
74 prefs->SetLastLaunchTime(inactive_app_id, inactive_launch);
76 // Set launch time for an active app.
77 std::string active_app_id = app_ids_[1];
78 base::Time active_launch = time_now -
79 base::TimeDelta::FromDays(EphemeralAppService::kAppKeepThreshold);
80 prefs->SetLastLaunchTime(active_app_id, active_launch);
82 // Perform garbage collection.
83 content::WindowedNotificationObserver uninstall_signal(
84 chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
85 content::Source<Profile>(browser()->profile()));
86 GarbageCollectEphemeralApps();
87 uninstall_signal.Wait();
89 ExtensionService* service = ExtensionSystem::Get(browser()->profile())
90 ->extension_service();
91 EXPECT_TRUE(service);
92 EXPECT_FALSE(service->GetInstalledExtension(inactive_app_id));
93 EXPECT_TRUE(service->GetInstalledExtension(active_app_id));