diff options
| author | tanaka takashi <isazaka@gmail.com> | 2026-09-02 03:14:05 +0900 |
|---|---|---|
| committer | tanaka takashi <isazaka@gmail.com> | 2026-09-02 03:14:05 +0900 |
| commit | 82bb55f66071b452e3bc7adeb09eafb5003de11f (patch) | |
| tree | 01d48a68273594fc2ed480d837724562dd6fb05d /doc/Testing-Results.md | |
| parent | f5439335e1d18ee577e2b7c1e67f7844f9f235ac (diff) | |
feat: PDF Viewer translation via context menu and two-mode Action Popupv0.1.0
Add Firefox built-in PDF Viewer support using only public WebExtensions
APIs: a selection context menu ("選択したテキストを翻訳") starts a
translation and the toolbar Action Popup shows the streaming result.
No content-script injection into the privileged PDF Viewer, no PDF.js
internals, no separate windows, no custom viewer (Specifications.md §4.6).
Specification alignment (Phase 1)
- Specifications.md: new requirements PDF-01..04 (PDF selection
translation), CTX-01..03 (context menu translation), POP-01..06
(popup two modes); SEL-06 updated to route PDF through the menus API;
section 13.4 adds a 14-item manual PDF verification checklist; section
15 removes "Firefox内蔵PDF Viewerへの対応" from out-of-scope
- Design.md: architecture diagram with the menus path, menu-translation
component, menus permission, popup translation-result state machine
(idle/starting/streaming/completed/error/cancelled), shared translation
state (§9.2), context-menu integration phase, test plan and API audit
checklist items (menus permission scope, no PDF Viewer internals)
- Security.md: menus permission restricted to selection-context
translation; PDF Viewer treated as privileged browser UI (no injection,
no wrappedJSObject/cloneInto/exportFunction, no internal DOM access);
menus.OnClickData.selectionText treated as untrusted input passing the
same validation pipeline; popup result rendering stays textContent-only
Background (Phase 2)
- translation-service.js (new): the single translation pipeline shared by
every entry point - selection validation (type/trim/empty/control
chars/max length), prompt building, Ollama request, session/abort, and
the shared translation state (requestId, sourceText, translatedText,
status, model, error, startedAt, source). "source" is metadata only; a
PDF-specific translation engine does not exist
- menu-translation.js (new): validates menus.OnClickData.selectionText
and starts a sink-less translation observed via GET_POPUP_STATE
- message-router.js: routes port translations through the shared service;
new runtime messages GET_POPUP_STATE and REGENERATE_LAST; popup-state
port handler broadcasts live state (initial push + every chunk/status
change) so an open popup shows streaming progress in real time
- index.js: registers the selection context menu (contexts: ["selection"]
only, no menus.onShown) and calls browser.action.openPopup()
synchronously inside the click user gesture, catching failures so a
popup-open problem never breaks the translation itself
- manifest.json: permissions now ["storage", "menus"]
- settings-service.js: __resetCacheForTests hook for test isolation
Popup two-mode UI (Phase 3)
- popup.html/js/css: mode nav (設定 / 翻訳). Translation mode shows
status, model, streaming text (textContent only), user-safe error, and
copy (Clipboard API only, no execCommand fallback), regenerate (new
requestId reusing the stored source text) and a settings shortcut.
Closing the popup never cancels the request; reopening shows the
latest text and continues receiving chunks live. Initial mode: active
(starting/streaming) translation wins, otherwise the last tab the user
picked is restored (storage.local.popupMode, default settings)
Fresh-install model auto-selection
- translation-service.js ensureModelConfigured(): when storage.model is
empty, pick the first model from the running Ollama and persist it
before translating, mirroring the popup/options auto-select. A user who
never opened any settings UI can translate immediately; when Ollama is
unreachable a clear OLLAMA_UNAVAILABLE message is shown
User-safe error details
- detailForUser(): strips URLs (no internal host names echoed to the UI),
caps length at 120 chars, drops full JSON response bodies, and hides
meaningless low-level network errors so the popover/popup shows the
base message plus at most a short, safe detail
Tests: 85 passed, 0 failed
- selectionText validation (untrusted input pipeline)
- menu selection -> translation -> popup state streaming/completed
- empty selection rejected without starting a request
- streaming status transitions observed through GET_POPUP_STATE
- Ollama unreachable surfaces a user-safe error into popup state
- newer request replaces older state (abort semantics)
- regenerateLast reuses source text with a fresh requestId
- popup-state port receives live broadcasts; wrong port names ignored
- fresh-install auto-select persists the first Ollama model
- error detail sanitization (URL stripping, length cap, JSON drop)
- popup/options smoke tests updated for the two-mode markup
- setupRouter resets the shared settings cache for test isolation
Docs: README documents the two-mode popup and PDF flow; Testing-Results
records automated results and the manual PDF checklist (to be executed).
No git-side surprises: this commit was created explicitly on request
(requirement 18 of the PDF task had deferred commits until now).
Diffstat (limited to 'doc/Testing-Results.md')
| -rw-r--r-- | doc/Testing-Results.md | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/doc/Testing-Results.md b/doc/Testing-Results.md index b2cf153..a9abf8a 100644 --- a/doc/Testing-Results.md +++ b/doc/Testing-Results.md @@ -6,7 +6,7 @@ 実行環境: Firefox系ブラウザ(Geckoエンジン)で `tests/test.html` を実行。npm / Node.js 不使用の自作ランナー。 -**結果: 71 passed, 0 failed** +**結果: 85 passed, 0 failed** ### カバレッジ @@ -28,6 +28,10 @@ | toExtensionError | 2 | AbortError→REQUEST_ABORTED、デフォルトコード | | TranslationSession | 2 | 新規要求で旧要求Abort+旧portへの通知、isActive/clear | | settings service | 3 | 保存/復元ラウンドトリップ、不正値フォールバック、onChangedキャッシュ更新 | +| selectionText validation | 1 | **context menu選択文字列のuntrusted validation**(型/trim/空/control文字/最大長) | +| context menu flow + popup state | 11 | **menus選択→翻訳→popup state streaming/completed**、空選択拒否、streaming状態遷移、Ollama停止時error、新規翻訳で旧state置換、regenerateLast、**popup-state portライブ配信**、誤名port拒否、**初期状態のモデル自動選択(未設定→先頭モデルを自動永続化)**、Ollama停止時のOLLAMA_UNAVAILABLE報告、エラー詳細のユーザー安全化(URL除去・長さ制限・JSON除去) | +| UI smoke (popup) | 1 | popup.js実DOM実行、2モードUI初期化、settings mode初期表示 | +| UI smoke (options) | 1 | options.js実DOM実行、言語/モデル/host反映 | | message router: port flow | 5 | started/chunk/completed伝送、**A→B新規要求でAがabort+stale chunk廃棄**、不正メッセージ破棄、OLLAMA_UNAVAILABLE、INVALID_SETTINGS | | message router: listModels | 2 | 正常系、非信頼sender拒否 | @@ -52,6 +56,27 @@ | 13 | ページ内のHTMLらしき文字列やscript文字列を選択してもDOM実行されない | ☐ 未実施 | | 14 | LLM出力にHTML文字列が含まれてもHTMLとして解釈されない | ☐ 未実施 | +## 2.1 PDF Viewer実機動作確認(context menu翻訳) + +以下はSpecifications.md §13.4の14項目です。実Firefox + 実Ollamaで確認してください。 + +| # | 確認項目 | 結果 | +|---|---|---| +| 1 | 通常Webページで文字列を選択する | ☐ 未実施 | +| 2 | context menuに「選択したテキストを翻訳」が表示される | ☐ 未実施 | +| 3 | menuからtranslationを開始できる | ☐ 未実施 | +| 4 | Firefox内蔵PDF ViewerでPDFを開く | ☐ 未実施 | +| 5 | PDF内のテキストを選択する | ☐ 未実施 | +| 6 | context menuに翻訳項目が表示される | ☐ 未実施 | +| 7 | `selectionText` が取得される | ☐ 未実施 | +| 8 | Action Popupが開く | ☐ 未実施 | +| 9 | Ollama streaming結果が逐次表示される | ☐ 未実施 | +| 10 | Copyが動く | ☐ 未実施 | +| 11 | Regenerateが動く | ☐ 未実施 | +| 12 | Ollama停止時に安全なエラー表示になる | ☐ 未実施 | +| 13 | HTML/script風のPDF文字列を選択しても実行されない | ☐ 未実施 | +| 14 | 新しい翻訳開始時に古いrequestが正しくcancelされる | ☐ 未実施 | + ## 3. セキュリティチェック | 項目 | 結果 | |
