* Toggles the experiment. * @param {string} id * @param {string} name * @param {boolean=} opt_on
(id, name, opt_on)
| 311 | * @param {boolean=} opt_on |
| 312 | */ |
| 313 | function toggleExperiment_(id, name, opt_on) { |
| 314 | const currentlyOn = isExperimentOn_(id); |
| 315 | const on = opt_on === undefined ? !currentlyOn : opt_on; |
| 316 | // Protect against accidental choice. |
| 317 | const confirmMessage = on |
| 318 | ? 'Do you really want to activate the AMP experiment?' |
| 319 | : 'Do you really want to deactivate the AMP experiment?'; |
| 320 | |
| 321 | showConfirmation_(`${confirmMessage}: "${name}"`, () => { |
| 322 | switch (id) { |
| 323 | case EXPERIMENTAL_CHANNEL_ID: |
| 324 | setAmpOptInCookie_( |
| 325 | on ? AMP_OPT_IN_COOKIE.EXPERIMENTAL : AMP_OPT_IN_COOKIE.DISABLED |
| 326 | ); |
| 327 | break; |
| 328 | case BETA_CHANNEL_ID: |
| 329 | setAmpOptInCookie_( |
| 330 | on ? AMP_OPT_IN_COOKIE.BETA : AMP_OPT_IN_COOKIE.DISABLED |
| 331 | ); |
| 332 | break; |
| 333 | case NIGHTLY_CHANNEL_ID: |
| 334 | setAmpOptInCookie_( |
| 335 | on ? AMP_OPT_IN_COOKIE.NIGHTLY : AMP_OPT_IN_COOKIE.DISABLED |
| 336 | ); |
| 337 | break; |
| 338 | default: |
| 339 | toggleExperiment(window, id, on); |
| 340 | } |
| 341 | update(); |
| 342 | }); |
| 343 | } |
| 344 | |
| 345 | /** |
| 346 | * Shows confirmation and calls callback if it's approved. |
nothing calls this directly
no test coverage detected