1 // Copyright 2020 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.
4 
5 #include "chrome/browser/ui/webui/settings/chromeos/os_settings_section.h"
6 
7 #include "base/test/scoped_feature_list.h"
8 #include "chrome/browser/ui/webui/settings/chromeos/constants/setting.mojom.h"
9 #include "chromeos/constants/chromeos_features.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 
12 namespace chromeos {
13 namespace settings {
14 
TEST(OsSettingsSectionTest,SectionWithFlag)15 TEST(OsSettingsSectionTest, SectionWithFlag) {
16   base::test::ScopedFeatureList scoped_feature_list;
17   scoped_feature_list.InitAndEnableFeature(
18       chromeos::features::kOsSettingsDeepLinking);
19 
20   // Sections should not incur modification.
21   EXPECT_EQ("internet", OsSettingsSection::GetDefaultModifiedUrl(
22                             /*type=*/mojom::SearchResultType::kSection,
23                             /*id=*/{.section = mojom::Section::kNetwork},
24                             /*url_to_modify=*/"internet"));
25 }
26 
TEST(OsSettingsSectionTest,SectionNoFlag)27 TEST(OsSettingsSectionTest, SectionNoFlag) {
28   base::test::ScopedFeatureList scoped_feature_list;
29   scoped_feature_list.InitAndDisableFeature(
30       chromeos::features::kOsSettingsDeepLinking);
31 
32   // Deep linking disabled, should not modify.
33   EXPECT_EQ("internet", OsSettingsSection::GetDefaultModifiedUrl(
34                             /*type=*/mojom::SearchResultType::kSection,
35                             /*id=*/{.section = mojom::Section::kNetwork},
36                             /*url_to_modify=*/"internet"));
37 }
38 
TEST(OsSettingsSectionTest,SubpageWithFlag)39 TEST(OsSettingsSectionTest, SubpageWithFlag) {
40   base::test::ScopedFeatureList scoped_feature_list;
41   scoped_feature_list.InitAndEnableFeature(
42       chromeos::features::kOsSettingsDeepLinking);
43 
44   // Subpages should not incur modification.
45   EXPECT_EQ("networks?type=WiFi",
46             OsSettingsSection::GetDefaultModifiedUrl(
47                 /*type=*/mojom::SearchResultType::kSubpage,
48                 /*id=*/{.subpage = mojom::Subpage::kWifiNetworks},
49                 /*url_to_modify=*/"networks?type=WiFi"));
50 }
51 
TEST(OsSettingsSectionTest,SubpageNoFlag)52 TEST(OsSettingsSectionTest, SubpageNoFlag) {
53   base::test::ScopedFeatureList scoped_feature_list;
54   scoped_feature_list.InitAndDisableFeature(
55       chromeos::features::kOsSettingsDeepLinking);
56 
57   // Deep linking disabled, should not modify.
58   EXPECT_EQ("networks?type=WiFi",
59             OsSettingsSection::GetDefaultModifiedUrl(
60                 /*type=*/mojom::SearchResultType::kSubpage,
61                 /*id=*/{.subpage = mojom::Subpage::kWifiNetworks},
62                 /*url_to_modify=*/"networks?type=WiFi"));
63 }
64 
TEST(OsSettingsSectionTest,SettingWithFlag)65 TEST(OsSettingsSectionTest, SettingWithFlag) {
66   base::test::ScopedFeatureList scoped_feature_list;
67   scoped_feature_list.InitAndEnableFeature(
68       chromeos::features::kOsSettingsDeepLinking);
69 
70   // Settings should have settingId added
71   EXPECT_EQ("networks?settingId=4",
72             OsSettingsSection::GetDefaultModifiedUrl(
73                 /*type=*/mojom::SearchResultType::kSetting,
74                 /*id=*/{.setting = mojom::Setting::kWifiOnOff},
75                 /*url_to_modify=*/"networks"));
76 }
77 
TEST(OsSettingsSectionTest,SettingExistingQueryWithFlag)78 TEST(OsSettingsSectionTest, SettingExistingQueryWithFlag) {
79   base::test::ScopedFeatureList scoped_feature_list;
80   scoped_feature_list.InitAndEnableFeature(
81       chromeos::features::kOsSettingsDeepLinking);
82 
83   // Settings with existing query parameters should have settingId added.
84   EXPECT_EQ("networks?type=WiFi&settingId=4",
85             OsSettingsSection::GetDefaultModifiedUrl(
86                 /*type=*/mojom::SearchResultType::kSetting,
87                 /*id=*/{.setting = mojom::Setting::kWifiOnOff},
88                 /*url_to_modify=*/"networks?type=WiFi"));
89 }
90 
TEST(OsSettingsSectionTest,SettingNoFlag)91 TEST(OsSettingsSectionTest, SettingNoFlag) {
92   base::test::ScopedFeatureList scoped_feature_list;
93   scoped_feature_list.InitAndDisableFeature(
94       chromeos::features::kOsSettingsDeepLinking);
95 
96   // Deep linking disabled, should not modify.
97   EXPECT_EQ("networks?type=WiFi",
98             OsSettingsSection::GetDefaultModifiedUrl(
99                 /*type=*/mojom::SearchResultType::kSetting,
100                 /*id=*/{.setting = mojom::Setting::kWifiOnOff},
101                 /*url_to_modify=*/"networks?type=WiFi"));
102 }
103 
104 }  // namespace settings
105 }  // namespace chromeos
106