1 #include "gtest/gtest.h"
2
3 #include "mozilla/net/HttpAuthUtils.h"
4 #include "mozilla/Preferences.h"
5 #include "nsNetUtil.h"
6
7 namespace mozilla {
8 namespace net {
9
10 #define TEST_PREF "network.http_test.auth_utils"
11
TEST(TestHttpAuthUtils,Bug1351301)12 TEST(TestHttpAuthUtils, Bug1351301) {
13 nsCOMPtr<nsIURI> url;
14 nsAutoCString spec;
15
16 ASSERT_EQ(Preferences::SetCString(TEST_PREF, "bar.com"), NS_OK);
17 spec = "http://bar.com";
18 ASSERT_EQ(NS_NewURI(getter_AddRefs(url), spec), NS_OK);
19 ASSERT_EQ(auth::URIMatchesPrefPattern(url, TEST_PREF), true);
20
21 spec = "http://foo.bar.com";
22 ASSERT_EQ(NS_NewURI(getter_AddRefs(url), spec), NS_OK);
23 ASSERT_EQ(auth::URIMatchesPrefPattern(url, TEST_PREF), true);
24
25 spec = "http://foobar.com";
26 ASSERT_EQ(NS_NewURI(getter_AddRefs(url), spec), NS_OK);
27 ASSERT_EQ(auth::URIMatchesPrefPattern(url, TEST_PREF), false);
28
29 ASSERT_EQ(Preferences::SetCString(TEST_PREF, ".bar.com"), NS_OK);
30 spec = "http://foo.bar.com";
31 ASSERT_EQ(NS_NewURI(getter_AddRefs(url), spec), NS_OK);
32 ASSERT_EQ(auth::URIMatchesPrefPattern(url, TEST_PREF), true);
33
34 spec = "http://bar.com";
35 ASSERT_EQ(NS_NewURI(getter_AddRefs(url), spec), NS_OK);
36 ASSERT_EQ(auth::URIMatchesPrefPattern(url, TEST_PREF), false);
37
38 ASSERT_EQ(Preferences::ClearUser(TEST_PREF), NS_OK);
39 }
40
41 } // namespace net
42 } // namespace mozilla
43