summaryrefslogtreecommitdiffstats
path: root/chrome/browser/history/top_sites_database_unittest.cc
blob: abd681e487385b49ba171b973a77527de7f73832 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/file_path.h"
#include "base/file_util.h"
#include "base/scoped_temp_dir.h"
#include "chrome/browser/history/top_sites_database.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace history {

class TopSitesDatabaseTest : public testing::Test {
 protected:
  virtual void SetUp() {
    // Get a temporary directory for the test DB files.
    ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
    file_name_ = temp_dir_.path().AppendASCII("TestTopSites.db");
  }

  ScopedTempDir temp_dir_;
  FilePath file_name_;
};

TEST_F(TopSitesDatabaseTest, UpgradeToVersion2) {
  TopSitesDatabase db;
  ASSERT_TRUE(db.Init(file_name_));

  // Create a version 1 table. SQLite doesn't support DROP COLUMN with
  // ALTER TABLE. Hence, we recreate a table here.
  ASSERT_TRUE(db.db_->Execute("DROP TABLE IF EXISTS thumbnails"));
  ASSERT_TRUE(db.db_->Execute("CREATE TABLE thumbnails ("
                              "url LONGVARCHAR PRIMARY KEY,"
                              "url_rank INTEGER ,"
                              "title LONGVARCHAR,"
                              "thumbnail BLOB,"
                              "redirects LONGVARCHAR,"
                              "boring_score DOUBLE DEFAULT 1.0, "
                              "good_clipping INTEGER DEFAULT 0, "
                              "at_top INTEGER DEFAULT 0, "
                              "last_updated INTEGER DEFAULT 0)"));
  db.meta_table_.SetVersionNumber(1);

  // Make sure the table meets the version 1 criteria.
  ASSERT_EQ(1, db.meta_table_.GetVersionNumber());
  ASSERT_FALSE(db.db_->DoesColumnExist("thumbnails", "load_completed"));

  // Upgrade to version 2.
  ASSERT_TRUE(db.UpgradeToVersion2());

  // Make sure the table meets the version 2 criteria.
  ASSERT_EQ(2, db.meta_table_.GetVersionNumber());
  ASSERT_TRUE(db.db_->DoesColumnExist("thumbnails", "load_completed"));
}

}  // namespace history