content/media/webspeech/recognition/test/FakeSpeechRecognitionService.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "nsThreadUtils.h"
michael@0 8
michael@0 9 #include "FakeSpeechRecognitionService.h"
michael@0 10
michael@0 11 #include "SpeechRecognition.h"
michael@0 12 #include "SpeechRecognitionAlternative.h"
michael@0 13 #include "SpeechRecognitionResult.h"
michael@0 14 #include "SpeechRecognitionResultList.h"
michael@0 15 #include "nsIObserverService.h"
michael@0 16 #include "mozilla/Services.h"
michael@0 17
michael@0 18 namespace mozilla {
michael@0 19
michael@0 20 using namespace dom;
michael@0 21
michael@0 22 NS_IMPL_ISUPPORTS(FakeSpeechRecognitionService, nsISpeechRecognitionService, nsIObserver)
michael@0 23
michael@0 24 FakeSpeechRecognitionService::FakeSpeechRecognitionService()
michael@0 25 {
michael@0 26 }
michael@0 27
michael@0 28 FakeSpeechRecognitionService::~FakeSpeechRecognitionService()
michael@0 29 {
michael@0 30 }
michael@0 31
michael@0 32 NS_IMETHODIMP
michael@0 33 FakeSpeechRecognitionService::Initialize(WeakPtr<SpeechRecognition> aSpeechRecognition)
michael@0 34 {
michael@0 35 mRecognition = aSpeechRecognition;
michael@0 36 nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
michael@0 37 obs->AddObserver(this, SPEECH_RECOGNITION_TEST_EVENT_REQUEST_TOPIC, false);
michael@0 38 obs->AddObserver(this, SPEECH_RECOGNITION_TEST_END_TOPIC, false);
michael@0 39 return NS_OK;
michael@0 40 }
michael@0 41
michael@0 42 NS_IMETHODIMP
michael@0 43 FakeSpeechRecognitionService::ProcessAudioSegment(AudioSegment* aAudioSegment)
michael@0 44 {
michael@0 45 return NS_OK;
michael@0 46 }
michael@0 47
michael@0 48 NS_IMETHODIMP
michael@0 49 FakeSpeechRecognitionService::SoundEnd()
michael@0 50 {
michael@0 51 return NS_OK;
michael@0 52 }
michael@0 53
michael@0 54 NS_IMETHODIMP
michael@0 55 FakeSpeechRecognitionService::Abort()
michael@0 56 {
michael@0 57 return NS_OK;
michael@0 58 }
michael@0 59
michael@0 60 NS_IMETHODIMP
michael@0 61 FakeSpeechRecognitionService::Observe(nsISupports* aSubject, const char* aTopic, const char16_t* aData)
michael@0 62 {
michael@0 63 MOZ_ASSERT(mRecognition->mTestConfig.mFakeRecognitionService,
michael@0 64 "Got request to fake recognition service event, but "
michael@0 65 TEST_PREFERENCE_FAKE_RECOGNITION_SERVICE " is not set");
michael@0 66
michael@0 67 if (!strcmp(aTopic, SPEECH_RECOGNITION_TEST_END_TOPIC)) {
michael@0 68 nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
michael@0 69 obs->RemoveObserver(this, SPEECH_RECOGNITION_TEST_EVENT_REQUEST_TOPIC);
michael@0 70 obs->RemoveObserver(this, SPEECH_RECOGNITION_TEST_END_TOPIC);
michael@0 71
michael@0 72 return NS_OK;
michael@0 73 }
michael@0 74
michael@0 75 const nsDependentString eventName = nsDependentString(aData);
michael@0 76
michael@0 77 if (eventName.EqualsLiteral("EVENT_RECOGNITIONSERVICE_ERROR")) {
michael@0 78 mRecognition->DispatchError(SpeechRecognition::EVENT_RECOGNITIONSERVICE_ERROR,
michael@0 79 SpeechRecognitionErrorCode::Network, // TODO different codes?
michael@0 80 NS_LITERAL_STRING("RECOGNITIONSERVICE_ERROR test event"));
michael@0 81
michael@0 82 } else if (eventName.EqualsLiteral("EVENT_RECOGNITIONSERVICE_FINAL_RESULT")) {
michael@0 83 nsRefPtr<SpeechEvent> event =
michael@0 84 new SpeechEvent(mRecognition,
michael@0 85 SpeechRecognition::EVENT_RECOGNITIONSERVICE_FINAL_RESULT);
michael@0 86
michael@0 87 event->mRecognitionResultList = BuildMockResultList();
michael@0 88 NS_DispatchToMainThread(event);
michael@0 89 }
michael@0 90
michael@0 91 return NS_OK;
michael@0 92 }
michael@0 93
michael@0 94 SpeechRecognitionResultList*
michael@0 95 FakeSpeechRecognitionService::BuildMockResultList()
michael@0 96 {
michael@0 97 SpeechRecognitionResultList* resultList = new SpeechRecognitionResultList(mRecognition);
michael@0 98 SpeechRecognitionResult* result = new SpeechRecognitionResult(mRecognition);
michael@0 99 SpeechRecognitionAlternative* alternative = new SpeechRecognitionAlternative(mRecognition);
michael@0 100
michael@0 101 alternative->mTranscript = NS_LITERAL_STRING("Mock final result");
michael@0 102 alternative->mConfidence = 0.0f;
michael@0 103
michael@0 104 result->mItems.AppendElement(alternative);
michael@0 105 resultList->mItems.AppendElement(result);
michael@0 106
michael@0 107 return resultList;
michael@0 108 }
michael@0 109
michael@0 110 } // namespace mozilla

mercurial