File: file_manager_string_util_unittest.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (58 lines) | stat: -rw-r--r-- 2,053 bytes parent folder | download | duplicates (7)
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
57
58
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ash/file_manager/file_manager_string_util.h"

#include "ash/system/time/date_helper.h"
#include "base/i18n/rtl.h"
#include "chrome/test/base/chrome_ash_test_base.h"
#include "chromeos/ash/components/settings/scoped_timezone_settings.h"
#include "testing/gtest/include/gtest/gtest.h"

class FileManagerStringUtilTest : public ChromeAshTestBase {
 public:
  FileManagerStringUtilTest(const FileManagerStringUtilTest&) = delete;
  FileManagerStringUtilTest& operator=(const FileManagerStringUtilTest&) =
      delete;
  FileManagerStringUtilTest() = default;
  ~FileManagerStringUtilTest() override = default;

  void SetDefaultLocale(const std::string& locale) {
    base::i18n::SetICUDefaultLocale(locale);
    ash::DateHelper::GetInstance()->ResetForTesting();
  }
};

TEST_F(FileManagerStringUtilTest, GetLocaleBasedWeekStart_Locale) {
  const struct DateTestData {
    const char* locale;
    int start_of_week;
  } kDateTestData[] = {
      // Australia uses Monday as the start day of the week.
      {"en_AU", 1},
      // United States uses Sunday as the start day of the week.
      {"en_US", 0},
      // Afghanistan uses Saturday as the start day of the week.
      {"ps-AF", 6},
      {"pa-PK", 0}};

  for (const auto& test : kDateTestData) {
    SetDefaultLocale(test.locale);
    EXPECT_EQ(GetLocaleBasedWeekStart(), test.start_of_week);
  }
}

TEST_F(FileManagerStringUtilTest, GetLocaleBasedWeekStart_Timezone) {
  const std::u16string kTimezoneIds[] = {
      u"GMT",      u"PST",      u"GMT+0800", u"GMT+1000", u"GMT+1300",
      u"GMT+1400", u"GMT-0800", u"GMT-1100", u"GMT-1200",
  };

  SetDefaultLocale("en_AU");
  for (const auto& timezone_id : kTimezoneIds) {
    ash::system::ScopedTimezoneSettings timezone_settings(timezone_id);
    // Regardless the timezone, week always starts with Monday for AU locale.
    EXPECT_EQ(GetLocaleBasedWeekStart(), 1);
  }
}