1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 // This test makes sure the HTTP authenticated sessions are correctly cleared
6 // when entering and leaving the private browsing mode.
11 var am
= Cc
["@mozilla.org/network/http-auth-manager;1"].getService(
15 const kHost1
= "pbtest3.example.com";
16 const kHost2
= "pbtest4.example.com";
19 const kBasic
= "basic";
20 const kRealm
= "realm";
21 const kDomain
= "example.com";
23 const kUser2
= "user2";
24 const kPassword
= "pass";
25 const kPassword2
= "pass2";
29 const NOT_PRIVATE
= false;
32 var domain
= { value
: kEmpty
},
33 user
= { value
: kEmpty
},
34 pass
= { value
: kEmpty
};
35 // simulate a login via HTTP auth outside of the private mode
47 // make sure the recently added auth entry is available outside the private browsing mode
60 Assert
.equal(domain
.value
, kDomain
);
61 Assert
.equal(user
.value
, kUser
);
62 Assert
.equal(pass
.value
, kPassword
);
64 // make sure the added auth entry is no longer accessible in private
65 domain
= { value
: kEmpty
};
66 user
= { value
: kEmpty
};
67 pass
= { value
: kEmpty
};
83 "Auth entry should not be retrievable after entering the private browsing mode"
86 Assert
.equal(domain
.value
, kEmpty
);
87 Assert
.equal(user
.value
, kEmpty
);
88 Assert
.equal(pass
.value
, kEmpty
);
91 // simulate a login via HTTP auth inside of the private mode
104 // make sure the recently added auth entry is available inside the private browsing mode
105 domain
= { value
: kEmpty
};
106 user
= { value
: kEmpty
};
107 pass
= { value
: kEmpty
};
120 Assert
.equal(domain
.value
, kDomain
);
121 Assert
.equal(user
.value
, kUser2
);
122 Assert
.equal(pass
.value
, kPassword2
);
125 // make sure the recently added auth entry is not available outside the private browsing mode
126 domain
= { value
: kEmpty
};
127 user
= { value
: kEmpty
};
128 pass
= { value
: kEmpty
};
142 "Auth entry should not be retrievable outside of private browsing mode"
145 Assert
.equal(domain
.value
, kEmpty
);
146 Assert
.equal(user
.value
, kEmpty
);
147 Assert
.equal(pass
.value
, kEmpty
);
150 // simulate leaving private browsing mode
151 Services
.obs
.notifyObservers(null, "last-pb-context-exited");
153 // make sure the added auth entry is no longer accessible in any privacy state
154 domain
= { value
: kEmpty
};
155 user
= { value
: kEmpty
};
156 pass
= { value
: kEmpty
};
158 // should throw (not available in public mode)
172 "Auth entry should not be retrievable after exiting the private browsing mode"
175 Assert
.equal(domain
.value
, kEmpty
);
176 Assert
.equal(user
.value
, kEmpty
);
177 Assert
.equal(pass
.value
, kEmpty
);
180 // should throw (no longer available in private mode)
194 "Auth entry should not be retrievable in private mode after exiting the private browsing mode"
197 Assert
.equal(domain
.value
, kEmpty
);
198 Assert
.equal(user
.value
, kEmpty
);
199 Assert
.equal(pass
.value
, kEmpty
);
202 do_throw("Unexpected exception while testing HTTP auth manager: " + e
);