Bug 1721178 - Add targeting trigger for successful captive portal login r=dmose

Differential Revision: https://phabricator.services.mozilla.com/D120730
This commit is contained in:
Andrei Oprea 2021-08-04 20:22:05 +00:00
Родитель b11b819e89
Коммит aa77a57273
4 изменённых файлов: 74 добавлений и 0 удалений

Просмотреть файл

@ -585,6 +585,44 @@ this.ASRouterTriggerListeners = new Map([
},
},
],
[
"captivePortalLogin",
{
id: "captivePortalLogin",
_initialized: false,
_triggerHandler: null,
init(triggerHandler) {
if (!this._initialized) {
Services.obs.addObserver(this, "captive-portal-login-success");
this._initialized = true;
}
this._triggerHandler = triggerHandler;
},
observe(aSubject, aTopic, aData) {
switch (aTopic) {
case "captive-portal-login-success":
const browser = Services.wm.getMostRecentBrowserWindow();
if (browser) {
this._triggerHandler(browser.gBrowser.selectedBrowser, {
id: this.id,
});
}
break;
}
},
uninit() {
if (this._initialized) {
this._triggerHandler = null;
this._initialized = false;
Services.obs.removeObserver(this, "captive-portal-login-success");
}
},
},
],
]);
const EXPORTED_SYMBOLS = ["ASRouterTriggerListeners"];

Просмотреть файл

@ -63,3 +63,22 @@ add_task(async function test_openURL_visit_counter_withPattern() {
"Third call should have count 2 for http://example.com"
);
});
add_task(async function test_captivePortalLogin() {
const stub = sinon.stub();
const captivePortalTrigger = ASRouterTriggerListeners.get(
"captivePortalLogin"
);
captivePortalTrigger.init(stub);
Services.obs.notifyObservers(this, "captive-portal-login-success", {});
Assert.ok(stub.called, "Called after login event");
captivePortalTrigger.uninit();
Services.obs.notifyObservers(this, "captive-portal-login-success", {});
Assert.equal(stub.callCount, 1, "Not called after uninit");
});

Просмотреть файл

@ -185,6 +185,18 @@
"additionalProperties": false,
"required": ["id"],
"description": "Happens when starting the browser or navigating to about:home/newtab"
},
{
"type": "object",
"properties": {
"id": {
"type": "string",
"enum": ["captivePortalLogin"]
}
},
"additionalProperties": false,
"required": ["id"],
"description": "Happens when the user successfully goes through a captive portal authentication flow."
}
]
}

Просмотреть файл

@ -119,3 +119,8 @@ On the newtab/homepage it reports the `source` as `newtab`.
let source = "newtab" | undefined;
let willShowDefaultPrompt = boolean;
```
### `captivePortalLogin`
Happens when the user successfully goes through a captive portal authentication flow.